Skip to content

[LLDB][OSX] Add a fallback support exe directory #103458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
Loading