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

via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 14 09:41:22 PDT 2024


Author: Walter Erquinigo
Date: 2024-08-14T12:41:19-04:00
New Revision: cce2271eab8173f5c27c1e99863a056a9430c252

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

LOG: [LLDB][OSX] Add a fallback support exe directory (#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.

Added: 
    

Modified: 
    lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm

Removed: 
    


################################################################################
diff  --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index f96e2cf80c5fac..b714f7be187aca 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,24 @@ 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. This last case is
+    // useful for supporting build systems like Bazel which in many cases prefer
+    // to place support binaries right next to dylibs.
     //
-    // 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.
-    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_lib(raw_path);
+    FileSpec support_dir_spec_bin =
+        support_dir_spec_lib.CopyByAppendingPathComponent("/../bin");
+    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