Skip to content

Commit

Permalink
[lldb] Add a function to check if lldb is running in an interactive s…
Browse files Browse the repository at this point in the history
…ession

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
  • Loading branch information
JDevlieghere committed May 3, 2022
1 parent 3d08c77 commit b945b62
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lldb/include/lldb/Host/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Host/common/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions lldb/source/Host/macosx/objcxx/Host.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b945b62

Please sign in to comment.