Skip to content

Commit

Permalink
[lldb/Interpreter] Open saved transcript in GUI Editor
Browse files Browse the repository at this point in the history
This patch will automatically open LLDB's saved transcript file on the
graphical editor if lldb is running under an interactive graphical session.

This can be controlled by a new setting: `interpreter.open-transcript-in-editor`

rdar://92692106

Differential Revision: https://reviews.llvm.org/D137137

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
  • Loading branch information
medismailben committed Nov 4, 2022
1 parent cb30072 commit 902ba8b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lldb/include/lldb/Interpreter/CommandInterpreter.h
Expand Up @@ -559,6 +559,9 @@ class CommandInterpreter : public Broadcaster,
bool GetSaveSessionOnQuit() const;
void SetSaveSessionOnQuit(bool enable);

bool GetOpenTranscriptInEditor() const;
void SetOpenTranscriptInEditor(bool enable);

FileSpec GetSaveSessionDirectory() const;
void SetSaveSessionDirectory(llvm::StringRef path);

Expand Down
18 changes: 18 additions & 0 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Expand Up @@ -170,6 +170,17 @@ void CommandInterpreter::SetSaveSessionOnQuit(bool enable) {
m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, enable);
}

bool CommandInterpreter::GetOpenTranscriptInEditor() const {
const uint32_t idx = ePropertyOpenTranscriptInEditor;
return m_collection_sp->GetPropertyAtIndexAsBoolean(
nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
}

void CommandInterpreter::SetOpenTranscriptInEditor(bool enable) {
const uint32_t idx = ePropertyOpenTranscriptInEditor;
m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, enable);
}

FileSpec CommandInterpreter::GetSaveSessionDirectory() const {
const uint32_t idx = ePropertySaveSessionDirectory;
return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
Expand Down Expand Up @@ -3226,6 +3237,13 @@ bool CommandInterpreter::SaveTranscript(
result.AppendMessageWithFormat("Session's transcripts saved to %s\n",
output_file->c_str());

if (GetOpenTranscriptInEditor() && Host::IsInteractiveGraphicSession()) {
const FileSpec file_spec;
error = file->GetFileSpec(const_cast<FileSpec &>(file_spec));
if (error.Success())
Host::OpenFileInExternalEditor(file_spec, 1);
}

return true;
}

Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Interpreter/InterpreterProperties.td
Expand Up @@ -13,6 +13,10 @@ let Definition = "interpreter" in {
Global,
DefaultFalse,
Desc<"If true, LLDB will save the session's transcripts before quitting.">;
def OpenTranscriptInEditor: Property<"open-transcript-in-editor", "Boolean">,
Global,
DefaultTrue,
Desc<"If true, LLDB will open the saved session's transcripts in the external editor.">;
def SaveSessionDirectory: Property<"save-session-directory", "FileSpec">,
DefaultStringValue<"">,
Desc<"A path where LLDB will save the session's transcripts. This is particularly useful when you can't set the session file, for example when using `save-session-on-quit`.">;
Expand Down

0 comments on commit 902ba8b

Please sign in to comment.