Skip to content

Commit 4a44cf7

Browse files
committed
[lldb] Read the precise SDK for the current CU first.
This fixes an oversight made during the switch to precise compiler invocations. rdar://141013288
1 parent 57ab61a commit 4a44cf7

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ static std::string GetSDKPathFromDebugInfo(std::string m_description,
21482148
return {};
21492149
auto sdk_or_err = platform_sp->GetSDKPathFromDebugInfo(module);
21502150
if (!sdk_or_err) {
2151-
Debugger::ReportError("Error while parsing SDK path from debug-info: " +
2151+
Debugger::ReportError("Error while parsing SDK path from debug info: " +
21522152
toString(sdk_or_err.takeError()));
21532153
return {};
21542154
}
@@ -2825,9 +2825,29 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
28252825
FileSpec target_sdk_spec = target_sp ? target_sp->GetSDKPath() : FileSpec();
28262826
if (target_sdk_spec && FileSystem::Instance().Exists(target_sdk_spec)) {
28272827
swift_ast_sp->SetPlatformSDKPath(target_sdk_spec.GetPath());
2828+
LOG_PRINTF(GetLog(LLDBLog::Types), "Using target SDK override: %s",
2829+
target_sdk_spec.GetPath().c_str());
28282830
handled_sdk_path = true;
28292831
}
28302832

2833+
// Get the precise SDK from the symbol context.
2834+
if (cu)
2835+
if (auto platform_sp = Platform::GetHostPlatform()) {
2836+
auto sdk_or_err = platform_sp->GetSDKPathFromDebugInfo(*cu);
2837+
if (!sdk_or_err)
2838+
Debugger::ReportError("Error while parsing SDK path from debug info: " +
2839+
toString(sdk_or_err.takeError()));
2840+
else {
2841+
std::string sdk_path = GetSDKPath(m_description, *sdk_or_err);
2842+
if (!sdk_path.empty()) {
2843+
swift_ast_sp->SetPlatformSDKPath(sdk_path);
2844+
handled_sdk_path = true;
2845+
LOG_PRINTF(GetLog(LLDBLog::Types), "Using precise SDK: %s",
2846+
sdk_path.c_str());
2847+
}
2848+
}
2849+
}
2850+
28312851
if (!handled_sdk_path) {
28322852
for (size_t mi = 0; mi != num_images; ++mi) {
28332853
ModuleSP module_sp = modules.GetModuleAtIndex(mi);
@@ -2839,8 +2859,8 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
28392859
if (sdk_path.empty())
28402860
continue;
28412861

2842-
handled_sdk_path = true;
28432862
swift_ast_sp->SetPlatformSDKPath(sdk_path);
2863+
handled_sdk_path = true;
28442864
break;
28452865
}
28462866
}

lldb/test/API/lang/swift/xcode_sdk/TestSwiftXcodeSDK.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,26 @@ class TestSwiftXcodeSDK(lldbtest.TestBase):
1010
mydir = lldbtest.TestBase.compute_mydir(__file__)
1111
NO_DEBUG_INFO_TESTCASE = True
1212

13-
def check_log(self, log, expected_path):
13+
def check_log(self, log, expected_path, expect_precise):
1414
import io
1515
logfile = io.open(log, "r", encoding='utf-8')
16-
in_expr_log = 0
1716
found = 0
17+
precise = False
1818
for line in logfile:
19-
if (line.startswith(' SwiftASTContextForExpressions(module: "a", cu: "main.swift")::LogConfiguration()') and
20-
"SDK path" in line and expected_path in line):
19+
if not line.startswith(' SwiftASTContextForExpressions(module: "a", cu: "main.swift")'):
20+
continue
21+
if "Using precise SDK" in line:
22+
precise = True
23+
continue
24+
if "Override target.sdk-path" in line:
25+
precise = False
26+
continue
27+
if not '::LogConfiguration()' in line:
28+
continue
29+
if "SDK path" in line and expected_path in line:
2130
found += 1
2231
self.assertEqual(found, 1)
32+
self.assertEqual(precise, expect_precise)
2333

2434
@swiftTest
2535
@skipUnlessDarwin
@@ -33,7 +43,7 @@ def test_decode(self):
3343
lldbutil.run_to_name_breakpoint(self, 'main')
3444

3545
self.expect("expression 1")
36-
self.check_log(log, "MacOSX")
46+
self.check_log(log, "MacOSX", True)
3747

3848
@swiftTest
3949
@skipUnlessDarwin
@@ -52,7 +62,7 @@ def test_decode_sim(self):
5262
lldbutil.run_to_name_breakpoint(self, 'main')
5363

5464
self.expect("expression 1")
55-
self.check_log(log, "iPhoneSimulator")
65+
self.check_log(log, "iPhoneSimulator", True)
5666

5767
@swiftTest
5868
@skipUnlessDarwin
@@ -72,4 +82,4 @@ def test_override(self):
7282
lldbutil.run_to_name_breakpoint(self, 'main')
7383

7484
self.expect("expression 1")
75-
self.check_log(log, ios_sdk)
85+
self.check_log(log, ios_sdk, False)

0 commit comments

Comments
 (0)