Skip to content

Commit 6041c74

Browse files
authored
Revert "[lldb][HostInfoMacOSX] Try to use DW_AT_LLVM_sysroot instead of xcrun when looking up SDK" (llvm#129621)
Reverts llvm#128712 ``` ******************** TEST 'lldb-unit :: SymbolFile/DWARF/./SymbolFileDWARFTests/10/14' FAILED ******************** Script(shard): -- GTEST_OUTPUT=json:/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/unittests/SymbolFile/DWARF/./SymbolFileDWARFTests-lldb-unit-1021-10-14.json GTEST_SHUFFLE=1 GTEST_TOTAL_SHARDS=14 GTEST_SHARD_INDEX=10 GTEST_RANDOM_SEED=62233 /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/unittests/SymbolFile/DWARF/./SymbolFileDWARFTests -- Script: -- /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/unittests/SymbolFile/DWARF/./SymbolFileDWARFTests --gtest_filter=SDKPathParsingTests/SDKPathParsingMultiparamTests.TestSDKPathFromDebugInfo/6 -- /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp:265: Failure Expected equality of these values: found_mismatch Which is: true expect_mismatch Which is: false /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp:265 Expected equality of these values: found_mismatch Which is: true expect_mismatch Which is: false ```
1 parent c1aebd4 commit 6041c74

File tree

7 files changed

+18
-71
lines changed

7 files changed

+18
-71
lines changed

lldb/include/lldb/Host/macosx/HostInfoMacOSX.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ class HostInfoMacOSX : public HostInfoPosix {
3232
static FileSpec GetXcodeDeveloperDirectory();
3333

3434
/// Query xcrun to find an Xcode SDK directory.
35-
///
36-
/// Note, this is an expensive operation if the SDK we're querying
37-
/// does not exist in an Xcode installation path on the host.
3835
static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options);
3936
static llvm::Expected<llvm::StringRef> FindSDKTool(XcodeSDK sdk,
4037
llvm::StringRef tool);

lldb/include/lldb/Utility/XcodeSDK.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLDB_UTILITY_SDK_H
1010
#define LLDB_UTILITY_SDK_H
1111

12-
#include "lldb/Utility/FileSpec.h"
1312
#include "lldb/lldb-forward.h"
1413
#include "llvm/ADT/StringRef.h"
1514
#include "llvm/Support/VersionTuple.h"
@@ -24,7 +23,6 @@ namespace lldb_private {
2423
/// An abstraction for Xcode-style SDKs that works like \ref ArchSpec.
2524
class XcodeSDK {
2625
std::string m_name;
27-
FileSpec m_sysroot;
2826

2927
public:
3028
/// Different types of Xcode SDKs.
@@ -64,8 +62,6 @@ class XcodeSDK {
6462
/// directory component of a path one would pass to clang's -isysroot
6563
/// parameter. For example, "MacOSX.10.14.sdk".
6664
XcodeSDK(std::string &&name) : m_name(std::move(name)) {}
67-
XcodeSDK(std::string name, FileSpec sysroot)
68-
: m_name(std::move(name)), m_sysroot(std::move(sysroot)) {}
6965
static XcodeSDK GetAnyMacOS() { return XcodeSDK("MacOSX.sdk"); }
7066

7167
/// The merge function follows a strict order to maintain monotonicity:
@@ -83,7 +79,6 @@ class XcodeSDK {
8379
llvm::VersionTuple GetVersion() const;
8480
Type GetType() const;
8581
llvm::StringRef GetString() const;
86-
const FileSpec &GetSysroot() const;
8782
/// Whether this Xcode SDK supports Swift.
8883
bool SupportsSwift() const;
8984

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,9 +1425,6 @@ PlatformDarwin::ResolveSDKPathFromDebugInfo(Module &module) {
14251425

14261426
auto [sdk, _] = std::move(*sdk_or_err);
14271427

1428-
if (FileSystem::Instance().Exists(sdk.GetSysroot()))
1429-
return sdk.GetSysroot().GetPath();
1430-
14311428
auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk});
14321429
if (!path_or_err)
14331430
return llvm::createStringError(

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -993,26 +993,21 @@ XcodeSDK SymbolFileDWARF::ParseXcodeSDK(CompileUnit &comp_unit) {
993993
const char *sdk = cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr);
994994
if (!sdk)
995995
return {};
996-
std::string sysroot =
996+
const char *sysroot =
997997
cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
998+
// Register the sysroot path remapping with the module belonging to
999+
// the CU as well as the one belonging to the symbol file. The two
1000+
// would be different if this is an OSO object and module is the
1001+
// corresponding debug map, in which case both should be updated.
1002+
ModuleSP module_sp = comp_unit.GetModule();
1003+
if (module_sp)
1004+
module_sp->RegisterXcodeSDK(sdk, sysroot);
9981005

999-
// RegisterXcodeSDK calls into xcrun which is not aware of CLT, which is
1000-
// expensive.
1001-
if (sysroot.find("/Library/Developer/CommandLineTools/SDKs") != 0) {
1002-
// Register the sysroot path remapping with the module belonging to
1003-
// the CU as well as the one belonging to the symbol file. The two
1004-
// would be different if this is an OSO object and module is the
1005-
// corresponding debug map, in which case both should be updated.
1006-
ModuleSP module_sp = comp_unit.GetModule();
1007-
if (module_sp)
1008-
module_sp->RegisterXcodeSDK(sdk, sysroot);
1009-
1010-
ModuleSP local_module_sp = m_objfile_sp->GetModule();
1011-
if (local_module_sp && local_module_sp != module_sp)
1012-
local_module_sp->RegisterXcodeSDK(sdk, sysroot);
1013-
}
1006+
ModuleSP local_module_sp = m_objfile_sp->GetModule();
1007+
if (local_module_sp && local_module_sp != module_sp)
1008+
local_module_sp->RegisterXcodeSDK(sdk, sysroot);
10141009

1015-
return {sdk, FileSpec{std::move(sysroot)}};
1010+
return {sdk};
10161011
}
10171012

10181013
size_t SymbolFileDWARF::ParseFunctions(CompileUnit &comp_unit) {

lldb/source/Utility/XcodeSDK.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ XcodeSDK::Type XcodeSDK::GetType() const {
142142

143143
llvm::StringRef XcodeSDK::GetString() const { return m_name; }
144144

145-
const FileSpec &XcodeSDK::GetSysroot() const { return m_sysroot; }
146-
147145
bool XcodeSDK::Info::operator<(const Info &other) const {
148146
return std::tie(type, version, internal) <
149147
std::tie(other.type, other.version, other.internal);
@@ -155,24 +153,17 @@ bool XcodeSDK::Info::operator==(const Info &other) const {
155153
}
156154

157155
void XcodeSDK::Merge(const XcodeSDK &other) {
158-
auto add_internal_sdk_suffix = [](llvm::StringRef sdk) {
159-
return (sdk.substr(0, sdk.size() - 3) + "Internal.sdk").str();
160-
};
161-
162156
// The "bigger" SDK always wins.
163157
auto l = Parse();
164158
auto r = other.Parse();
165159
if (l < r)
166160
*this = other;
167161
else {
168162
// The Internal flag always wins.
169-
if (!l.internal && r.internal) {
170-
if (llvm::StringRef(m_name).ends_with(".sdk"))
171-
m_name = add_internal_sdk_suffix(m_name);
172-
173-
if (m_sysroot.GetFileNameExtension() == ".sdk")
174-
m_sysroot.SetFilename(add_internal_sdk_suffix(m_sysroot.GetFilename()));
175-
}
163+
if (llvm::StringRef(m_name).ends_with(".sdk"))
164+
if (!l.internal && r.internal)
165+
m_name =
166+
m_name.substr(0, m_name.size() - 3) + std::string("Internal.sdk");
176167
}
177168
}
178169

lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -307,28 +307,13 @@ SDKPathParsingTestData sdkPathParsingTestCases[] = {
307307
.expect_internal_sdk = true,
308308
.expect_sdk_path_pattern = "Internal.sdk"},
309309

310-
/// Two CUs with a public (non-CommandLineTools) SDK each
311-
{.input_sdk_paths = {"/Path/To/SDKs/iPhoneOS14.1.sdk",
312-
"/Path/To/SDKs/MacOSX11.3.sdk"},
313-
.expect_mismatch = false,
314-
.expect_internal_sdk = false,
315-
.expect_sdk_path_pattern = "iPhoneOS14.1.sdk"},
316-
317-
/// One CU with CommandLineTools and the other a public SDK
310+
/// Two CUs with an internal SDK each
318311
{.input_sdk_paths =
319312
{"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.1.sdk",
320-
"/Path/To/SDKs/MacOSX11.3.sdk"},
313+
"/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk"},
321314
.expect_mismatch = false,
322315
.expect_internal_sdk = false,
323316
.expect_sdk_path_pattern = "iPhoneOS14.1.sdk"},
324-
325-
/// One CU with CommandLineTools and the other an internal SDK
326-
{.input_sdk_paths =
327-
{"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.1.sdk",
328-
"/Path/To/SDKs/MacOSX11.3.Internal.sdk"},
329-
.expect_mismatch = false,
330-
.expect_internal_sdk = true,
331-
.expect_sdk_path_pattern = "iPhoneOS14.1.Internal.sdk"},
332317
};
333318

334319
INSTANTIATE_TEST_SUITE_P(SDKPathParsingTests, SDKPathParsingMultiparamTests,

lldb/unittests/Utility/XcodeSDKTest.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,12 @@ TEST(XcodeSDKTest, ParseTest) {
3434
EXPECT_EQ(XcodeSDK("MacOSX10.9.sdk").GetVersion(), llvm::VersionTuple(10, 9));
3535
EXPECT_EQ(XcodeSDK("MacOSX10.15.4.sdk").GetVersion(), llvm::VersionTuple(10, 15));
3636
EXPECT_EQ(XcodeSDK("MacOSX.sdk").IsAppleInternalSDK(), false);
37-
EXPECT_EQ(
38-
XcodeSDK("MacOSX.sdk", FileSpec{"/Path/To/MacOSX.sdk"}).GetSysroot(),
39-
FileSpec("/Path/To/MacOSX.sdk"));
4037
EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").GetType(), XcodeSDK::MacOSX);
4138
EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").GetVersion(),
4239
llvm::VersionTuple(10, 15));
4340
EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").IsAppleInternalSDK(), true);
44-
EXPECT_FALSE(XcodeSDK("MacOSX10.15.Internal.sdk").GetSysroot());
4541
EXPECT_EQ(XcodeSDK().GetType(), XcodeSDK::unknown);
4642
EXPECT_EQ(XcodeSDK().GetVersion(), llvm::VersionTuple());
47-
EXPECT_FALSE(XcodeSDK().GetSysroot());
4843
}
4944

5045
TEST(XcodeSDKTest, MergeTest) {
@@ -65,14 +60,6 @@ TEST(XcodeSDKTest, MergeTest) {
6560
XcodeSDK empty;
6661
empty.Merge(XcodeSDK("MacOSX10.14.Internal.sdk"));
6762
EXPECT_EQ(empty.GetString(), llvm::StringRef("MacOSX10.14.Internal.sdk"));
68-
EXPECT_FALSE(empty.GetSysroot());
69-
empty.Merge(XcodeSDK("MacOSX9.5.Internal.sdk", FileSpec{"/Path/To/9.5.sdk"}));
70-
EXPECT_FALSE(empty.GetSysroot());
71-
empty.Merge(XcodeSDK("MacOSX12.5.sdk", FileSpec{"/Path/To/12.5.sdk"}));
72-
EXPECT_EQ(empty.GetSysroot(), FileSpec{"/Path/To/12.5.sdk"});
73-
empty.Merge(XcodeSDK("MacOSX11.5.Internal.sdk",
74-
FileSpec{"/Path/To/12.5.Internal.sdk"}));
75-
EXPECT_EQ(empty.GetSysroot(), FileSpec{"/Path/To/12.5.Internal.sdk"});
7663
}
7764

7865
#ifndef _WIN32

0 commit comments

Comments
 (0)