When we build the Clang module compilation command (e.g., when
a user requests import of a module via expression @import Foundation),
LLDB will try to determine which SDK directory to use as the sysroot.
However, it currently does so by simply enumerating the SDKs directory
and picking the last one that's appropriate for module compilation
(see PlatformDarwin::GetSDKDirectoryForModules). That means if we have
multiple platform SDKs installed (e.g., a public and internal one), we
may pick the wrong one by chance.
On Darwin platforms we emit the SDK path that a object
file was compiled against into DWARF (using DW_AT_LLVM_sysroot
and DW_AT_APPLE_sdk). For Swift debugging, we already parse the SDK
path from debug-info if we can.
This patch mimicks the Swift behaviour for non-Swift languages. I.e.,
if we can get the SDK path from debug-info, do so. Otherwise, fall back
to the old heuristic.
rdar://110407148
Only remaining question is whether we want to limit this to just Objective-C and Swift. Going through each compile unit for C++ seems like a lot of work for something that we won't use
@aprantl