Skip to content

Add warning message to session save when transcript isn't saved. #109020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lldb/source/Commands/CommandObjectSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class CommandObjectSessionSave : public CommandObjectParsed {
: CommandObjectParsed(interpreter, "session save",
"Save the current session transcripts to a file.\n"
"If no file if specified, transcripts will be "
"saved to a temporary file.",
"saved to a temporary file.\n"
"Note: transcripts will only be saved if "
"interpreter.save-transcript is true.\n",
"session save [file]") {
AddSimpleArgumentList(eArgTypePath, eArgRepeatOptional);
}
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3308,6 +3308,10 @@ bool CommandInterpreter::SaveTranscript(
result.SetStatus(eReturnStatusSuccessFinishNoResult);
result.AppendMessageWithFormat("Session's transcripts saved to %s\n",
output_file->c_str());
if (!GetSaveTranscript())
result.AppendError(
"Note: the setting interpreter.save-transcript is set to false, so the "
"transcript might not have been recorded.");

if (GetOpenTranscriptInEditor() && Host::IsInteractiveGraphicSession()) {
const FileSpec file_spec;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/InterpreterProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let Definition = "interpreter" in {
def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">,
Global,
DefaultFalse,
Desc<"If true, LLDB will save the session's transcripts before quitting.">;
Desc<"If true, LLDB will save the session's transcripts before quitting. Note: transcripts will only be saved if interpreter.save-transcript is true.">;
def OpenTranscriptInEditor: Property<"open-transcript-in-editor", "Boolean">,
Global,
DefaultTrue,
Expand Down
32 changes: 32 additions & 0 deletions lldb/test/API/commands/session/save/TestSessionSave.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def test_session_save(self):
interpreter.HandleCommand("session save", res)
self.assertTrue(res.Succeeded())
raw += self.raw_transcript_builder(cmd, res)
# Also check that we don't print an error message about an empty transcript.
self.assertNotIn("interpreter.save-transcript is set to false", res.GetError())

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

@no_debug_info_test
def test_session_save_no_transcript_warning(self):
interpreter = self.dbg.GetCommandInterpreter()

self.runCmd("settings set interpreter.save-transcript false")

# These commands won't be saved, so are arbitrary.
commands = [
"p 1",
"settings set interpreter.save-session-on-quit true",
"fr v",
"settings set interpreter.echo-comment-commands true",
]

for command in commands:
res = lldb.SBCommandReturnObject()
interpreter.HandleCommand(command, res)

output_file = self.getBuildArtifact("my-session")

res = lldb.SBCommandReturnObject()
interpreter.HandleCommand("session save " + output_file, res)
self.assertTrue(res.Succeeded())
# We should warn about the setting being false.
self.assertIn("interpreter.save-transcript is set to false", res.GetError())
self.assertTrue(
os.path.getsize(output_file) == 0,
"Output file should be empty since we didn't save the transcript.",
)

@no_debug_info_test
def test_session_save_on_quit(self):
raw = ""
Expand Down
Loading