Skip to content

Commit cce2271

Browse files
[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.
1 parent d2f0d99 commit cce2271

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
124124
return g_program_filespec;
125125
}
126126

127+
/// Resolve the given candidate support dir and return true if it's valid.
128+
static bool ResolveAndVerifyCandidateSupportDir(FileSpec &path) {
129+
FileSystem::Instance().Resolve(path);
130+
return FileSystem::Instance().IsDirectory(path);
131+
};
132+
127133
bool HostInfoMacOSX::ComputeSupportExeDirectory(FileSpec &file_spec) {
128134
FileSpec lldb_file_spec = GetShlibDir();
129135
if (!lldb_file_spec)
@@ -144,16 +150,24 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
144150
#endif
145151
} else {
146152
// Find the bin path relative to the lib path where the cmake-based
147-
// OS X .dylib lives. This is not going to work if the bin and lib
148-
// dir are not both in the same dir.
153+
// OS X .dylib lives. We try looking first at a possible sibling `bin`
154+
// directory, and then at the `lib` directory itself. This last case is
155+
// useful for supporting build systems like Bazel which in many cases prefer
156+
// to place support binaries right next to dylibs.
149157
//
150-
// It is not going to work to do it by the executable path either,
158+
// It is not going to work to do it by the executable path,
151159
// as in the case of a python script, the executable is python, not
152160
// the lldb driver.
153-
raw_path.append("/../bin");
154-
FileSpec support_dir_spec(raw_path);
155-
FileSystem::Instance().Resolve(support_dir_spec);
156-
if (!FileSystem::Instance().IsDirectory(support_dir_spec)) {
161+
FileSpec support_dir_spec_lib(raw_path);
162+
FileSpec support_dir_spec_bin =
163+
support_dir_spec_lib.CopyByAppendingPathComponent("/../bin");
164+
FileSpec support_dir_spec;
165+
166+
if (ResolveAndVerifyCandidateSupportDir(support_dir_spec_bin)) {
167+
support_dir_spec = support_dir_spec_bin;
168+
} else if (ResolveAndVerifyCandidateSupportDir(support_dir_spec_lib)) {
169+
support_dir_spec = support_dir_spec_lib;
170+
} else {
157171
Log *log = GetLog(LLDBLog::Host);
158172
LLDB_LOG(log, "failed to find support directory");
159173
return false;

0 commit comments

Comments
 (0)