This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add another fallback to GetXcodeSDK
ClosedPublic

Authored by JDevlieghere on Oct 5 2020, 7:03 PM.

Details

Summary

If we tried getting the SDK from xcrun with the developer dir set and it failed, try without the developer dir.

Diff Detail

Event Timeline

JDevlieghere requested review of this revision.Oct 5 2020, 7:03 PM
JDevlieghere created this revision.

So this is adding a fallback that ignores DEVELOPER_DIR if it is set, but doesn't exist? Is that really desirable, or am I misunderstanding the patch? I would expect LLDB to fail hard if the DEVELOPER_DIR in the environment is wrong and not silently ignore it...

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

Can we delete this comment? I find it more confusing than helpful...

So this is adding a fallback that ignores DEVELOPER_DIR if it is set, but doesn't exist? Is that really desirable, or am I misunderstanding the patch? I would expect LLDB to fail hard if the DEVELOPER_DIR in the environment is wrong and not silently ignore it...

It's slightly more subtle than that, it falls back to running xcrun without a developer dir if we couldn't find the desired SDK with the developer dir set. It doesn't mean the developer dir is invalid or doesn't exist, it just means we couldn't find the SDK there. Imagine for the sake of argument that you're running an Xcode that has no SDKs and that this Xcode is not xcode-selected. Based on lldb's location in LLDB.framework it will do an xcrun with the developer set to the Xcode without any SDKs and that will fail. With this patch, when that happens, we'll fall back to trying the xcode-selected by running xcrun without a developer dir specified. I know it sounds like a contrived example but that's exactly what I was running into...

aprantl added inline comments.Oct 6 2020, 12:58 PM
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
411

perhaps add

bool have_developer_dir = !developer_dir.empty()`
433

and here if (!have_developer_dir)

to avoid silently ignoring an explicitly specified DEVELOPER_DIR

aprantl added inline comments.Oct 6 2020, 2:59 PM
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
424

Can you use a fresh std::string with a different name here?

aprantl accepted this revision.Oct 6 2020, 3:00 PM

Apart from a cosmetic detail (inline) this LGTM!

This revision is now accepted and ready to land.Oct 6 2020, 3:00 PM
aprantl added inline comments.Oct 6 2020, 3:42 PM
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
378

In theory we could make this a StringRef and then have one less copy. Not important though.

423

std::string shlib_developer_dir(...); ?

Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2020, 3:55 PM