Skip to content

Commit

Permalink
Add warning message to session save when transcript isn't saved. (l…
Browse files Browse the repository at this point in the history
…lvm#109020)

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`. By default, `interpreter.save-transcript`
is false. See llvm#90703 for context.

I'm making a small update here to our `session save` messaging and some
help docs to clarify for users that aren't aware of this change. Maybe
`interpreter.save-transcript` could be true by default as well. Any
feedback welcome.

# Tests
```
bin/lldb-dotest -p TestSessionSave
```

---------

Co-authored-by: Tom Yang <[email protected]>
  • Loading branch information
2 people authored and Kyvangka1610 committed Oct 5, 2024
1 parent 9cfb604 commit 885587f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
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

0 comments on commit 885587f

Please sign in to comment.