Skip to content

Deserialize search path options in ProcessModule (NFCi) #3353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 55 additions & 20 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,11 +1814,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
// Add Swift interfaces in the .dSYM at the end of the search paths.
// .swiftmodules win over .swiftinterfaces, when they are loaded
// directly from the .swift_ast section.
//
// FIXME: Since these paths also end up in the scratch context, we
// would need a mechanism to ensure that and newer versions
// (in the library evolution sense, not the date on disk) win
// over older versions of the same .swiftinterface.
if (auto dsym = GetDSYMBundle(module)) {
llvm::SmallString<256> path(*dsym);
llvm::Triple triple(swift_ast_sp->GetTriple());
Expand Down Expand Up @@ -1927,7 +1922,7 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
return ModuleSP();
}

/// Scan a newly added lldb::Module fdor Swift modules and report any errors in
/// Scan a newly added lldb::Module for Swift modules and report any errors in
/// its module SwiftASTContext to Target.
static void
ProcessModule(ModuleSP module_sp, std::string m_description,
Expand Down Expand Up @@ -2046,20 +2041,60 @@ ProcessModule(ModuleSP module_sp, std::string m_description,

if (ast_context->HasErrors())
return;
if (use_all_compiler_flags ||
target.GetExecutableModulePointer() == module_sp.get()) {

const auto &opts = ast_context->GetSearchPathOptions();
module_search_paths.insert(module_search_paths.end(),
opts.ImportSearchPaths.begin(),
opts.ImportSearchPaths.end());
for (const auto &fwsp : opts.FrameworkSearchPaths)
framework_search_paths.push_back({fwsp.Path, fwsp.IsSystem});
for (const std::string &arg : ast_context->GetClangArguments()) {
extra_clang_args.push_back(arg);
LOG_VERBOSE_PRINTF(LIBLLDB_LOG_TYPES, "adding Clang argument \"%s\".",
arg.c_str());
}

// Load search path options from the module.
if (!use_all_compiler_flags &&
target.GetExecutableModulePointer() != module_sp.get())
return;

// Add Swift interfaces in the .dSYM at the end of the search paths.
// .swiftmodules win over .swiftinterfaces, when they are loaded
// directly from the .swift_ast section.
//
// FIXME: Since these paths end up in the scratch context, we would
// need a mechanism to ensure that and newer versions (in the
// library evolution sense, not the date on disk) win over
// older versions of the same .swiftinterface.
if (auto dsym = GetDSYMBundle(*module_sp)) {
llvm::SmallString<256> path(*dsym);
llvm::Triple triple(ast_context->GetTriple());
StringRef arch = llvm::Triple::getArchTypeName(triple.getArch());
llvm::sys::path::append(path, "Contents", "Resources", "Swift", arch);
bool exists = false;
llvm::sys::fs::is_directory(path, exists);
if (exists)
module_search_paths.push_back(std::string(path));
}

// Create a one-off CompilerInvocation as a place to load the
// deserialized search path options into.
SymbolFile *sym_file = module_sp->GetSymbolFile();
if (!sym_file)
return;
bool found_swift_modules = false;
bool got_serialized_options = false;
llvm::SmallString<0> error;
llvm::raw_svector_ostream errs(error);
swift::CompilerInvocation invocation;
if (DeserializeAllCompilerFlags(invocation, *module_sp, m_description, errs,
got_serialized_options,
found_swift_modules)) {
// TODO: After removing DeserializeAllCompilerFlags from
// CreateInstance(per-Module), errs will need to be
// collected here and surfaced.
}

const auto &opts = invocation.getSearchPathOptions();
module_search_paths.insert(module_search_paths.end(),
opts.ImportSearchPaths.begin(),
opts.ImportSearchPaths.end());
for (const auto &fwsp : opts.FrameworkSearchPaths)
framework_search_paths.push_back({fwsp.Path, fwsp.IsSystem});
auto &clang_opts = invocation.getClangImporterOptions().ExtraArgs;
for (const std::string &arg : clang_opts) {
extra_clang_args.push_back(arg);
LOG_VERBOSE_PRINTF(LIBLLDB_LOG_TYPES, "adding Clang argument \"%s\".",
arg.c_str());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,21 @@ def dotest(self, remap):
found_rel = 0
found_abs = 0
found_ovl = 0
in_scratch_context = False
logfile = open(log, "r")
for line in logfile:
self.assertFalse("remapped -iquote" in line)
if " remapped " in line:
if line[:-1].endswith('/user'): found_abs += 1;
continue
if "error: " in line and "Foo" in line:
errs += 1
continue
if line.startswith(" SwiftASTContextForExpressions"):
in_scratch_context = True
if " remapped " in line:
if line[:-1].endswith('/user'):
found_abs += 1;
continue
if not in_scratch_context:
continue
if 'user/iquote-path' in line: found_iquote += 1; continue
if 'user/I-single' in line: found_i1 += 1; continue
if 'user/I-double' in line: found_i2 += 1; continue
Expand All @@ -116,13 +122,13 @@ def dotest(self, remap):

if remap:
self.assertEqual(errs, 0, "expected no module import error")
# Module context + scratch context.
self.assertEqual(found_iquote, 2)
self.assertEqual(found_i1, 2)
self.assertEqual(found_i2, 2)
self.assertEqual(found_f, 2)
# Counting occurences in the scratch context.
self.assertEqual(found_iquote, 1)
self.assertEqual(found_i1, 1)
self.assertEqual(found_i2, 1)
self.assertEqual(found_f, 1)
self.assertEqual(found_rel, 0)
self.assertEqual(found_abs, 1)
self.assertEqual(found_ovl, 2)
self.assertEqual(found_ovl, 1)
else:
self.assertTrue(errs > 0, "expected module import error")
self.assertGreater(errs, 0, "expected module import error")
1 change: 1 addition & 0 deletions lldb/test/Shell/Swift/astcontext_error.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# RUN: %target-swiftc -g %S/Inputs/ContextError.swift
# RUN: %lldb ContextError -s %s | FileCheck %S/Inputs/ContextError.swift

# Test that re-running a process doesn't emit bogus warnings.
br set -p "here"
run
run