Skip to content

Commit b011e77

Browse files
author
walter erquinigo
committed
[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.
1 parent 101acff commit b011e77

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

Lines changed: 18 additions & 6 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,22 @@ 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.
149155
//
150-
// It is not going to work to do it by the executable path either,
156+
// It is not going to work to do it by the executable path,
151157
// as in the case of a python script, the executable is python, not
152158
// the lldb driver.
159+
FileSpec support_dir_spec_lib(raw_path);
153160
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_bin(raw_path);
162+
FileSpec support_dir_spec;
163+
164+
if (ResolveAndVerifyCandidateSupportDir(support_dir_spec_bin)) {
165+
support_dir_spec = support_dir_spec_bin;
166+
} else if (ResolveAndVerifyCandidateSupportDir(support_dir_spec_lib)) {
167+
support_dir_spec = support_dir_spec_lib;
168+
} else {
157169
Log *log = GetLog(LLDBLog::Host);
158170
LLDB_LOG(log, "failed to find support directory");
159171
return false;

0 commit comments

Comments
 (0)