Skip to content

Commit 172f8d1

Browse files
committed
[lldb/Interpreter] Open saved transcript in GUI Editor
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 <[email protected]>
1 parent d0ac12d commit 172f8d1

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lldb/include/lldb/Interpreter/CommandInterpreter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ class CommandInterpreter : public Broadcaster,
551551
bool GetSaveSessionOnQuit() const;
552552
void SetSaveSessionOnQuit(bool enable);
553553

554+
bool GetOpenTranscriptInEditor() const;
555+
void SetOpenTranscriptInEditor(bool enable);
556+
554557
FileSpec GetSaveSessionDirectory() const;
555558
void SetSaveSessionDirectory(llvm::StringRef path);
556559

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ void CommandInterpreter::SetSaveSessionOnQuit(bool enable) {
167167
m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, enable);
168168
}
169169

170+
bool CommandInterpreter::GetOpenTranscriptInEditor() const {
171+
const uint32_t idx = ePropertyOpenTranscriptInEditor;
172+
return m_collection_sp->GetPropertyAtIndexAsBoolean(
173+
nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
174+
}
175+
176+
void CommandInterpreter::SetOpenTranscriptInEditor(bool enable) {
177+
const uint32_t idx = ePropertyOpenTranscriptInEditor;
178+
m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, enable);
179+
}
180+
170181
FileSpec CommandInterpreter::GetSaveSessionDirectory() const {
171182
const uint32_t idx = ePropertySaveSessionDirectory;
172183
return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
@@ -3209,6 +3220,13 @@ bool CommandInterpreter::SaveTranscript(
32093220
result.AppendMessageWithFormat("Session's transcripts saved to %s\n",
32103221
output_file->c_str());
32113222

3223+
if (GetOpenTranscriptInEditor() && Host::IsInteractiveGraphicSession()) {
3224+
const FileSpec file_spec;
3225+
error = file->GetFileSpec(const_cast<FileSpec &>(file_spec));
3226+
if (error.Success())
3227+
Host::OpenFileInExternalEditor(file_spec, 1);
3228+
}
3229+
32123230
return true;
32133231
}
32143232

lldb/source/Interpreter/InterpreterProperties.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ let Definition = "interpreter" in {
1313
Global,
1414
DefaultFalse,
1515
Desc<"If true, LLDB will save the session's transcripts before quitting.">;
16+
def OpenTranscriptInEditor: Property<"open-transcript-in-editor", "Boolean">,
17+
Global,
18+
DefaultTrue,
19+
Desc<"If true, LLDB will open the saved session's transcripts in the external editor.">;
1620
def SaveSessionDirectory: Property<"save-session-directory", "FileSpec">,
1721
DefaultStringValue<"">,
1822
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`.">;

0 commit comments

Comments
 (0)