void SetPrompt(const char *) = delete;
bool GetUseExternalEditor() const;
-
bool SetUseExternalEditor(bool use_external_editor_p);
+ llvm::StringRef GetExternalEditor() const;
+
+ bool SetExternalEditor(llvm::StringRef editor);
+
bool GetUseColor() const;
bool SetUseColor(bool use_color);
bool run_in_shell = true,
bool hide_stderr = false);
- static llvm::Error OpenFileInExternalEditor(const FileSpec &file_spec,
+ static llvm::Error OpenFileInExternalEditor(llvm::StringRef editor,
+ const FileSpec &file_spec,
uint32_t line_no);
/// Check if we're running in an interactive graphical session.
Global,
DefaultFalse,
Desc<"Whether to use an external editor or not.">;
+ def ExternalEditor: Property<"external-editor", "String">,
+ Global,
+ DefaultStringValue<"">,
+ Desc<"External editor to use when use-external-editor is enabled.">;
def UseColor: Property<"use-color", "Boolean">,
Global,
DefaultTrue,
return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
}
+llvm::StringRef Debugger::GetExternalEditor() const {
+ const uint32_t idx = ePropertyExternalEditor;
+ return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, "");
+}
+
+bool Debugger::SetExternalEditor(llvm::StringRef editor) {
+ const uint32_t idx = ePropertyExternalEditor;
+ return m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, editor);
+}
+
bool Debugger::GetUseColor() const {
const uint32_t idx = ePropertyUseColor;
return m_collection_sp->GetPropertyAtIndexAsBoolean(
#endif
#if !defined(__APPLE__)
-llvm::Error Host::OpenFileInExternalEditor(const FileSpec &file_spec,
+llvm::Error Host::OpenFileInExternalEditor(llvm::StringRef editor,
+ const FileSpec &file_spec,
uint32_t line_no) {
return llvm::errorCodeToError(
std::error_code(ENOTSUP, std::system_category()));
#endif // TARGET_OS_OSX
-llvm::Error Host::OpenFileInExternalEditor(const FileSpec &file_spec,
+llvm::Error Host::OpenFileInExternalEditor(llvm::StringRef editor,
+ const FileSpec &file_spec,
uint32_t line_no) {
#if !TARGET_OS_OSX
return llvm::errorCodeToError(
auto on_exit = llvm::make_scope_exit(
[&]() { AEDisposeDesc(&(file_and_line_desc.descContent)); });
- static std::optional<FSRef> g_app_fsref;
- static std::string g_app_error;
- static std::once_flag g_once_flag;
- std::call_once(g_once_flag, [&]() {
- if (const char *external_editor = ::getenv("LLDB_EXTERNAL_EDITOR")) {
- LLDB_LOG(log, "Looking for external editor: {0}", external_editor);
-
- FSRef app_fsref;
- CFCString editor_name(external_editor, kCFStringEncodingUTF8);
- long app_error = ::LSFindApplicationForInfo(
- /*inCreator=*/kLSUnknownCreator, /*inBundleID=*/NULL,
- /*inName=*/editor_name.get(), /*outAppRef=*/&app_fsref,
- /*outAppURL=*/NULL);
- if (app_error == noErr) {
- g_app_fsref = app_fsref;
- } else {
- g_app_error =
- llvm::formatv("could not find external editor \"{0}\": "
- "LSFindApplicationForInfo returned error {1}",
- external_editor, app_error)
- .str();
- }
- }
- });
+ if (editor.empty()) {
+ if (const char *lldb_external_editor = ::getenv("LLDB_EXTERNAL_EDITOR"))
+ editor = lldb_external_editor;
+ }
- if (!g_app_error.empty())
- return llvm::createStringError(llvm::inconvertibleErrorCode(), g_app_error);
+ std::optional<FSRef> app_fsref;
+ if (!editor.empty()) {
+ LLDB_LOG(log, "Looking for external editor: {0}", editor);
+
+ app_fsref.emplace();
+ CFCString editor_name(editor.data(), kCFStringEncodingUTF8);
+ long app_error = ::LSFindApplicationForInfo(
+ /*inCreator=*/kLSUnknownCreator, /*inBundleID=*/NULL,
+ /*inName=*/editor_name.get(), /*outAppRef=*/&(*app_fsref),
+ /*outAppURL=*/NULL);
+ if (app_error != noErr)
+ return llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ llvm::formatv("could not find external editor \"{0}\": "
+ "LSFindApplicationForInfo returned error {1}",
+ editor, app_error));
+ }
// Build app launch parameters.
LSApplicationParameters app_params;
::memset(&app_params, 0, sizeof(app_params));
app_params.flags =
kLSLaunchDefaults | kLSLaunchDontAddToRecents | kLSLaunchDontSwitch;
- if (g_app_fsref)
- app_params.application = &(g_app_fsref.value());
+ if (app_fsref)
+ app_params.application = &(*app_fsref);
ProcessSerialNumber psn;
std::array<CFURLRef, 1> file_array = {file_URL.get()};
const FileSpec file_spec;
error = file->GetFileSpec(const_cast<FileSpec &>(file_spec));
if (error.Success()) {
- if (llvm::Error e = Host::OpenFileInExternalEditor(file_spec, 1))
+ if (llvm::Error e = Host::OpenFileInExternalEditor(
+ m_debugger.GetExternalEditor(), file_spec, 1))
result.AppendError(llvm::toString(std::move(e)));
}
}
bool already_shown = false;
SymbolContext frame_sc(
frame_sp->GetSymbolContext(eSymbolContextLineEntry));
- if (GetProcess()->GetTarget().GetDebugger().GetUseExternalEditor() &&
- frame_sc.line_entry.file && frame_sc.line_entry.line != 0) {
+ const Debugger &debugger = GetProcess()->GetTarget().GetDebugger();
+ if (debugger.GetUseExternalEditor() && frame_sc.line_entry.file &&
+ frame_sc.line_entry.line != 0) {
if (llvm::Error e = Host::OpenFileInExternalEditor(
- frame_sc.line_entry.file, frame_sc.line_entry.line)) {
+ debugger.GetExternalEditor(), frame_sc.line_entry.file,
+ frame_sc.line_entry.line)) {
LLDB_LOG_ERROR(GetLog(LLDBLog::Host), std::move(e),
"OpenFileInExternalEditor failed: {0}");
} else {
frame_sp->GetSymbolContext(eSymbolContextLineEntry));
if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file) {
if (llvm::Error e = Host::OpenFileInExternalEditor(
+ target->GetDebugger().GetExternalEditor(),
frame_sc.line_entry.file, frame_sc.line_entry.line)) {
LLDB_LOG_ERROR(GetLog(LLDBLog::Host), std::move(e),
"OpenFileInExternalEditor failed: {0}");
--- /dev/null
+REQUIRES: system-darwin
+RUN: %lldb -o 'settings set use-external-editor true' -o 'setting set external-editor foo' -o 'session save' -b 2>&1 | FileCheck %s
+RUN: LLDB_EXTERNAL_EDITOR="foo" %lldb -o 'settings set use-external-editor true' -o 'session save' -b 2>&1 | FileCheck %s
+CHECK: error: could not find external editor "foo": LSFindApplicationForInfo returned error