From b945b62cf35e1b45ffb9233958756743b2b5fd46 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Tue, 3 May 2022 15:04:45 -0700 Subject: [PATCH] [lldb] Add a function to check if lldb is running in an interactive session This patch adds a function to check if lldb is running in an interactive debug session. Currently this API only works on macOS. It's expected to be used in combination with Host::OpenFileInExternalEditor. Differential revision: https://reviews.llvm.org/D124872 --- lldb/include/lldb/Host/Host.h | 7 +++++++ lldb/source/Host/common/Host.cpp | 1 + lldb/source/Host/macosx/objcxx/Host.mm | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h index b78988721b5079..3b49b5e3935077 100644 --- a/lldb/include/lldb/Host/Host.h +++ b/lldb/include/lldb/Host/Host.h @@ -242,6 +242,13 @@ class Host { static bool OpenFileInExternalEditor(const FileSpec &file_spec, uint32_t line_no); + /// Check if we're running in an interactive graphical session. + /// + /// \return + /// True if we're running in an interactive graphical session. False if + /// we're not or don't know. + static bool IsInteractiveGraphicSession(); + static Environment GetEnvironment(); static std::unique_ptr diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index 28232eadd350be..e8c5ece9a4f6c4 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -575,6 +575,7 @@ bool Host::OpenFileInExternalEditor(const FileSpec &file_spec, return false; } +bool Host::IsInteractiveGraphicSession() { return false; } #endif std::unique_ptr Host::CreateDefaultConnection(llvm::StringRef url) { diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm index ca6a408642ae80..7c490f922128dd 100644 --- a/lldb/source/Host/macosx/objcxx/Host.mm +++ b/lldb/source/Host/macosx/objcxx/Host.mm @@ -32,6 +32,8 @@ #define LauncherXPCServiceErrorTypeKey "errorType" #define LauncherXPCServiceCodeTypeKey "errorCode" +#include +#include #endif #include "llvm/Support/Host.h" @@ -406,6 +408,16 @@ repeat with the_window in (get windows)\n\ #endif // TARGET_OS_OSX } +bool Host::IsInteractiveGraphicSession() { +#if !TARGET_OS_OSX + return false; +#else + auditinfo_addr_t info; + getaudit_addr(&info, sizeof(info)); + return info.ai_flags & AU_SESSION_FLAG_HAS_GRAPHIC_ACCESS; +#endif +} + Environment Host::GetEnvironment() { return Environment(*_NSGetEnviron()); } static bool GetMacOSXProcessCPUType(ProcessInstanceInfo &process_info) {