Skip to content

Commit e94f734

Browse files
author
Tom Yang
committed
Add warning message to session save when transcript isn't saved.
Somewhat recently, we made the change to hide the behavior to save LLDB session history to the transcript buffer behind the flag `interpreter.save-transcript`.
1 parent 554eaec commit e94f734

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

lldb/source/Commands/CommandObjectSession.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class CommandObjectSessionSave : public CommandObjectParsed {
1919
: CommandObjectParsed(interpreter, "session save",
2020
"Save the current session transcripts to a file.\n"
2121
"If no file if specified, transcripts will be "
22-
"saved to a temporary file.",
22+
"saved to a temporary file.\n"
23+
"Note: transcripts will only be saved if interpreter.save-transcript is true.\n",
2324
"session save [file]") {
2425
AddSimpleArgumentList(eArgTypePath, eArgRepeatOptional);
2526
}

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,6 +3308,8 @@ bool CommandInterpreter::SaveTranscript(
33083308
result.SetStatus(eReturnStatusSuccessFinishNoResult);
33093309
result.AppendMessageWithFormat("Session's transcripts saved to %s\n",
33103310
output_file->c_str());
3311+
if (!GetSaveTranscript())
3312+
result.AppendError("Note: the setting interpreter.save-transcript is set to false, so the transcript might not have been recorded.");
33113313

33123314
if (GetOpenTranscriptInEditor() && Host::IsInteractiveGraphicSession()) {
33133315
const FileSpec file_spec;

lldb/source/Interpreter/InterpreterProperties.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let Definition = "interpreter" in {
1616
def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">,
1717
Global,
1818
DefaultFalse,
19-
Desc<"If true, LLDB will save the session's transcripts before quitting.">;
19+
Desc<"If true, LLDB will save the session's transcripts before quitting. Note: transcripts will only be saved if interpreter.save-transcript is true.">;
2020
def OpenTranscriptInEditor: Property<"open-transcript-in-editor", "Boolean">,
2121
Global,
2222
DefaultTrue,

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def test_session_save(self):
8585
interpreter.HandleCommand("session save", res)
8686
self.assertTrue(res.Succeeded())
8787
raw += self.raw_transcript_builder(cmd, res)
88+
# Also check that we don't print an error message about an empty transcript.
89+
self.assertNotIn("interpreter.save-transcript is set to false", res.GetError())
8890

8991
with open(os.path.join(td.name, os.listdir(td.name)[0]), "r") as file:
9092
content = file.read()
@@ -93,6 +95,33 @@ def test_session_save(self):
9395
for line in lines:
9496
self.assertIn(line, content)
9597

98+
@no_debug_info_test
99+
def test_session_save_no_transcript_warning(self):
100+
interpreter = self.dbg.GetCommandInterpreter()
101+
102+
self.runCmd("settings set interpreter.save-transcript false")
103+
104+
# These commands won't be saved, so are arbitrary.
105+
commands = [
106+
"p 1",
107+
"settings set interpreter.save-session-on-quit true",
108+
"fr v",
109+
"settings set interpreter.echo-comment-commands true",
110+
]
111+
112+
for command in commands:
113+
res = lldb.SBCommandReturnObject()
114+
interpreter.HandleCommand(command, res)
115+
116+
output_file = self.getBuildArtifact('my-session')
117+
118+
res = lldb.SBCommandReturnObject()
119+
interpreter.HandleCommand("session save " + output_file, res)
120+
self.assertTrue(res.Succeeded())
121+
# We should warn about the setting being false.
122+
self.assertIn("interpreter.save-transcript is set to false", res.GetError())
123+
self.assertTrue(os.path.getsize(output_file) == 0, "Output file should be empty since we didn't save the transcript.")
124+
96125
@no_debug_info_test
97126
def test_session_save_on_quit(self):
98127
raw = ""

0 commit comments

Comments
 (0)