8000 Recompute runtime library search path after discovering the SDK · swiftlang/llvm-project@1a7340d · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a7340d

Browse files
committed
Recompute runtime library search path after discovering the SDK
This fixes a failure to import the Swift runtime library when debugging a program that was compiled without serialized earch path options. rdar://problem/59429786
1 parent 5e5c037 commit 1a7340d

File tree

4 files changed

+67
-17
lines changed

4 files67

-17
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS := -Xfrontend -no-serialize-debugging-options
3+
4+
include Makefile.rules
Lines changed: 39 additions & 0 deletions
31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import os
6+
import unittest2
7+
8+
9+
class TestSwiftRuntimeLibraryPath(lldbtest.TestBase):
10+
11+
mydir = lldbtest.TestBase.compute_mydir(__file__)
12+
NO_DEBUG_INFO_TESTCASE = True
13+
14+
@swiftTest
15+
@skipUnlessDarwin
16+
def test_allocator_self(self):
17+
"""That the default runtime library path can be recovered even if
18+
paths weren't serialized."""
19+
self.build()
20+
log = self.getBuildArtifact("types.log")
21+
command_result = lldb.SBCommandReturnObject()
22+
interpreter = self.dbg.GetCommandInterpreter()
23+
interpreter.HandleCommand("log enable lldb types -f "+log, command_result)
24+
25+
target, process, thread, bkpt = lldbutil.run_to_name_breakpoint(
26+
self, 'main')
27+
28+
self.expect("p 1")
29+
logfile = open(log, "r")
30+
in_expr_log = 0
+
found = 0
32+
for line in logfile:
33+
if line.startswith(" SwiftASTContextForExpressions::LogConfiguration"):
34+
in_expr_log += 1
35+
if in_expr_log and "Runtime library paths" in line and \
36+
"2 items" in line:
37+
found += 1
38+
self.assertEqual(in_expr_log, 1)
39+
self.assertEqual(found, 1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("I have loaded Swift successfully - break here")

lldb/source/Symbol/SwiftASTContext.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,17 +2719,16 @@ swift::SearchPathOptions &SwiftASTContext::GetSearchPathOptions() {
27192719
}
27202720

27212721
void SwiftASTContext::InitializeSearchPathOptions(
2722-
llvm::ArrayRef<std::string> module_search_paths,
2723-
llvm::ArrayRef<std::pair<std::string, bool>> framework_search_paths) {
2724-
swift::SearchPathOptions &search_path_opts =
2725-
GetCompilerInvocation().getSearchPathOptions();
2722+
llvm::ArrayRef<std::string> extra_module_search_paths,
2723+
llvm::ArrayRef<std::pair<std::string, bool>> extra_framework_search_paths) {
2724+
swift::CompilerInvocation &invocation = GetCompilerInvocation();
27262725

27272726
assert(!m_initialized_search_path_options);
27282727
m_initialized_search_path_options = true;
27292728

27302729
bool set_sdk = false;
2731-
if (!search_path_opts.SDKPath.empty()) {
2732-
FileSpec provided_sdk_path(search_path_opts.SDKPath);
2730+
if (!invocation.getSDKPath().empty()) {
2731+
FileSpec provided_sdk_path(invocation.getSDKPath());
27332732
if (FileSystem::Instance().Exists(provided_sdk_path)) {
27342733
// We don't check whether the SDK supports swift because we figure if
27352734
// someone is passing this to us on the command line (e.g., for the
@@ -2742,7 +2741,7 @@ void SwiftASTContext::InitializeSearchPathOptions(
27422741

27432742
if (FileSystem::Instance().Exists(platform_sdk) &&
27442743
SDKSupportsSwift(platform_sdk, SDKType::unknown)) {
2745-
search_path_opts.SDKPath = m_platform_sdk_path.c_str();
2744+
invocation.setSDKPath(m_platform_sdk_path.c_str());
27462745
set_sdk = true;
27472746
}
27482747
}
@@ -2763,38 +2762,45 @@ void SwiftASTContext::InitializeSearchPathOptions(
27632762
if (sdk.sdk_type != SDKType::unknown) {
27642763
auto dir = GetSDKDirectory(sdk.sdk_type, sdk.min_version_major,
27652764
sdk.min_version_minor);
2766-
search_path_opts.SDKPath = dir.AsCString("");
2765+
// Note that calling setSDKPath() also recomputes all paths that
2766+
// depend on the SDK path including the
2767+
// RuntimeLibraryImportPaths, which are *only* initialized
2768+
// through this mechanism.
2769+
invocation.setSDKPath(dir.AsCString(""));
27672770
}
27682771

2769-
std::vector<std::string>& lpaths = search_path_opts.LibrarySearchPaths;
2772+
std::vector<std::string> &lpaths =
2773+
invocation.getSearchPathOptions().LibrarySearchPaths;
27702774
lpaths.insert(lpaths.begin(), "/usr/lib/swift");
27712775
}
27722776

27732777
llvm::StringMap<bool> processed;
2778+
std::vector<std::string> &invocation_import_paths =
2779+
invocation.getSearchPathOptions().ImportSearchPaths;
27742780
// Add all deserialized paths to the map.
2775-
for (const auto &path : search_path_opts.ImportSearchPaths)
2781+
for (const auto &path : invocation_import_paths)
27762782
processed.insert({path, false});
27772783

27782784
// Add/unique all extra paths.
2779-
for (const auto &path : module_search_paths) {
2780-
search_path_opts.ImportSearchPaths.push_back(path);
2785+
for (const auto &path : extra_module_search_paths) {
27812786
auto it_notseen = processed.insert({path, false});
27822787
if (it_notseen.second)
2783-
search_path_opts.ImportSearchPaths.push_back(path);
2788+
invocation_import_paths.push_back(path);
27842789
}
27852790

27862791
// This preserves the IsSystem bit, but deduplicates entries ignoring it.
27872792
processed.clear();
2793+
auto &invocation_framework_paths =
2794+
invocation.getSearchPathOptions().FrameworkSearchPaths;
27882795
// Add all deserialized paths to the map.
2789-
for (const auto &path : search_path_opts.FrameworkSearchPaths)
2796+
for (const auto &path : invocation_framework_paths)
27902797
processed.insert({path.Path, path.IsSystem});
27912798

27922799
// Add/unique all extra paths.
2793-
for (const auto &path : framework_search_paths) {
2800+
for (const auto &path : extra_framework_search_paths) {
27942801
auto it_notseen = processed.insert(path);
27952802
if (it_notseen.second)
2796-
search_path_opts.FrameworkSearchPaths.push_back(
2797-
{path.first, path.second});
2803+
invocation_framework_paths.push_back({path.first, path.second});
27982804
}
27992805
}
28002806

0 commit comments

Comments
 (0)
0