Skip to content

Commit c5e417a

Browse files
committed
[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.
1 parent fb87e11 commit c5e417a

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,6 +3235,8 @@ bool CommandInterpreter::SaveTranscript(
32353235
if (output_file == std::nullopt || output_file->empty()) {
32363236
std::string now = llvm::to_string(std::chrono::system_clock::now());
32373237
std::replace(now.begin(), now.end(), ' ', '_');
3238+
// Can't have file name with colons on Windows
3239+
std::replace(now.begin(), now.end(), ':', '-');
32383240
const std::string file_name = "lldb_session_" + now + ".log";
32393241

32403242
FileSpec save_location = GetSaveSessionDirectory();

lldb/test/API/commands/session/save/TestSessionSave.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def raw_transcript_builder(self, cmd, res):
1919
raw += res.GetError()
2020
return raw
2121

22-
@skipIfWindows
2322
@no_debug_info_test
2423
def test_session_save(self):
2524
raw = ""
@@ -61,8 +60,7 @@ def test_session_save(self):
6160
self.assertFalse(res.Succeeded())
6261
raw += self.raw_transcript_builder(cmd, res)
6362

64-
tf = tempfile.NamedTemporaryFile()
65-
output_file = tf.name
63+
output_file = self.getBuildArtifact('my-session')
6664

6765
res = lldb.SBCommandReturnObject()
6866
interpreter.HandleCommand("session save " + output_file, res)
@@ -95,7 +93,6 @@ def test_session_save(self):
9593
for line in lines:
9694
self.assertIn(line, content)
9795

98-
@skipIfWindows
9996
@no_debug_info_test
10097
def test_session_save_on_quit(self):
10198
raw = ""

0 commit comments

Comments
 (0)