[Lldb-commits] [lldb] [LLDB][OSX] Add a fallback support exe directory (PR #103458)

Walter Erquinigo via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 13 14:15:03 PDT 2024


https://github.com/walter-erquinigo created https://github.com/llvm/llvm-project/pull/103458

LLDB on OSX is looking at a `bin` directory sibling to the `lib` one that contains liblldb for its supporting executables. This works well for CMake, however, for other build systems like bazel, it's not that easy to have that build structure, for which it's much easier to also use the `lib` directory as a fallback under the absence of `bin`.
This shouldn't break anything, but instead should make it a bit easier for LLDB to work with different build systems and folder structures.


>From b011e77a937f4279295c55169c6d3049bfe2eaa2 Mon Sep 17 00:00:00 2001
From: walter erquinigo <walter at modular.com>
Date: Tue, 13 Aug 2024 17:09:38 -0400
Subject: [PATCH] [LLDB][OSX] Add a fallback support exe directory

LLDB on OSX is looking at a `bin` directory sibling to the `lib` one that contains liblldb for its supporting executables. This works well for CMake, however, for other build systems like bazel, it's not that easy to have that build structure, for which it's much easier to also use the `lib` directory as a fallback under the absence of `bin`.
This shouldn't break anything, but instead should make it a bit easier for LLDB to work with different build systems and folder structures.
---
 .../Host/macosx/objcxx/HostInfoMacOSX.mm      | 24 ++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index f96e2cf80c5fac..02d02a21ad0955 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -124,6 +124,12 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
   return g_program_filespec;
 }
 
+/// Resolve the given candidate support dir and return true if it's valid.
+static bool ResolveAndVerifyCandidateSupportDir(FileSpec &path) {
+  FileSystem::Instance().Resolve(path);
+  return FileSystem::Instance().IsDirectory(path);
+};
+
 bool HostInfoMacOSX::ComputeSupportExeDirectory(FileSpec &file_spec) {
   FileSpec lldb_file_spec = GetShlibDir();
   if (!lldb_file_spec)
@@ -144,16 +150,22 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
 #endif
   } else {
     // Find the bin path relative to the lib path where the cmake-based
-    // OS X .dylib lives.  This is not going to work if the bin and lib
-    // dir are not both in the same dir.
+    // OS X .dylib lives. We try looking first at a possible sibling `bin`
+    // directory, and then at the `lib` directory itself.
     //
-    // It is not going to work to do it by the executable path either,
+    // It is not going to work to do it by the executable path,
     // as in the case of a python script, the executable is python, not
     // the lldb driver.
+    FileSpec support_dir_spec_lib(raw_path);
     raw_path.append("/../bin");
-    FileSpec support_dir_spec(raw_path);
-    FileSystem::Instance().Resolve(support_dir_spec);
-    if (!FileSystem::Instance().IsDirectory(support_dir_spec)) {
+    FileSpec support_dir_spec_bin(raw_path);
+    FileSpec support_dir_spec;
+
+    if (ResolveAndVerifyCandidateSupportDir(support_dir_spec_bin)) {
+      support_dir_spec = support_dir_spec_bin;
+    } else if (ResolveAndVerifyCandidateSupportDir(support_dir_spec_lib)) {
+      support_dir_spec = support_dir_spec_lib;
+    } else {
       Log *log = GetLog(LLDBLog::Host);
       LLDB_LOG(log, "failed to find support directory");
       return false;



More information about the lldb-commits mailing list