[Lldb-commits] [lldb] b945b62 - [lldb] Add a function to check if lldb is running in an interactive session

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue May 3 15:12:08 PDT 2022


Author: Jonas Devlieghere
Date: 2022-05-03T15:11:57-07:00
New Revision: b945b62cf35e1b45ffb9233958756743b2b5fd46

URL: https://github.com/llvm/llvm-project/commit/b945b62cf35e1b45ffb9233958756743b2b5fd46
DIFF: https://github.com/llvm/llvm-project/commit/b945b62cf35e1b45ffb9233958756743b2b5fd46.diff

LOG: [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

Added: 
    

Modified: 
    lldb/include/lldb/Host/Host.h
    lldb/source/Host/common/Host.cpp
    lldb/source/Host/macosx/objcxx/Host.mm

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h
index b78988721b507..3b49b5e393507 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<Connection>

diff  --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 28232eadd350b..e8c5ece9a4f6c 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<Connection> Host::CreateDefaultConnection(llvm::StringRef url) {

diff  --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm
index ca6a408642ae8..7c490f922128d 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 <bsm/audit.h>
+#include <bsm/audit_session.h>
 #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) {


        


More information about the lldb-commits mailing list