Skip to content

Commit e09e318

Browse files
Merge pull request #8594 from adrian-prantl/astblob-order
Register the symbol context's module first.
2 parents dc49097 + 7dbd6b7 commit e09e318

File tree

4 files changed

+71
-29
lines changed

4 files changed

+71
-29
lines changed

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -818,18 +818,17 @@ DYLIB_SWIFT_FLAGS= \
818818
-Xlinker -install_name -Xlinker "$(DYLIB_INSTALL_NAME)" \
819819
$(LD_EXTRAS)
820820
ifeq "$(DYLIB_HIDE_SWIFTMODULE)" ""
821-
DYLIB_SWIFT_FLAGS+= -Xlinker -add_ast_path -Xlinker $(DYLIB_NAME).swiftmodule
821+
DYLIB_SWIFT_FLAGS+= -Xlinker -add_ast_path -Xlinker $(MODULENAME).swiftmodule
822822
endif
823823
else
824824
DYLIB_SWIFT_FLAGS=$(LD_EXTRAS)
825+
ifeq "$(DYLIB_HIDE_SWIFTMODULE)" ""
826+
DYLIB_OBJECTS += $(BUILDDIR)/$(MODULENAME).o
827+
endif
825828
endif
829+
826830
$(DYLIB_FILENAME) : $(DYLIB_OBJECTS) $(MODULE_INTERFACE)
827831
@echo "### Linking dynamic library $(DYLIB_NAME)"
828-
ifneq "$(DYLIB_HIDE_SWIFTMODULE)" ""
829-
$(SWIFTC) $(patsubst -g,,$(SWIFTFLAGS)) \
830-
-emit-library $(DYLIB_SWIFT_FLAGS) -o $@ \
831-
$(patsubst %.swiftmodule.o,,$(DYLIB_OBJECTS))
832-
else
833832
ifneq "$(FRAMEWORK)" ""
834833
mkdir -p $(FRAMEWORK).framework/Versions/A/Headers
835834
mkdir -p $(FRAMEWORK).framework/Versions/A/Modules
@@ -846,7 +845,6 @@ endif
846845
endif
847846
$(SWIFTC) $(patsubst -g,,$(SWIFTFLAGS)) \
848847
-emit-library $(DYLIB_SWIFT_FLAGS) -o $@ $(DYLIB_OBJECTS)
849-
endif
850848
ifneq "$(CODESIGN)" ""
851849
$(CODESIGN) -s - "$(DYLIB_FILENAME)"
852850
endif

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

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,10 +2981,56 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
29812981
plugin_search_options.begin(),
29822982
plugin_search_options.end());
29832983

2984+
// Register the symbol context's module first. This makes it more
2985+
// likely that compatible AST blobs are found first, since then the
2986+
// local AST blobs overwrite any ones with the same import path from
2987+
// another dylib.
2988+
llvm::DenseSet<Module *> visited_modules;
2989+
llvm::StringMap<ModuleSP> all_modules;
29842990
for (size_t mi = 0; mi != num_images; ++mi) {
2985-
std::vector<std::string> module_names;
2986-
auto module_sp = target.GetImages().GetModuleAtIndex(mi);
2987-
swift_ast_sp->RegisterSectionModules(*module_sp, module_names);
2991+
auto image_sp = target.GetImages().GetModuleAtIndex(mi);
2992+
std::string path = image_sp->GetSpecificationDescription();
2993+
all_modules.insert({path, image_sp});
2994+
all_modules.insert({llvm::sys::path::filename(path), image_sp});
2995+
}
2996+
std::vector<std::string> module_names;
2997+
std::function<void(ModuleSP, unsigned)> scan_module =
2998+
[&](ModuleSP cur_module_sp, unsigned indent) {
2999+
if (!cur_module_sp ||
3000+
!visited_modules.insert(cur_module_sp.get()).second)
3001+
return;
3002+
swift_ast_sp->RegisterSectionModules(*cur_module_sp, module_names);
3003+
if (GetLog(LLDBLog::Types)) {
3004+
std::string spacer(indent, '-');
3005+
LOG_PRINTF(GetLog(LLDBLog::Types), "+%s Dependency scan: %s",
3006+
spacer.c_str(),
3007+
cur_module_sp->GetSpecificationDescription().c_str());
3008+
}
3009+
if (auto object = cur_module_sp->GetObjectFile()) {
3010+
FileSpecList file_list;
3011+
object->GetDependentModules(file_list);
3012+
for (auto &fs : file_list) {
3013+
if (ModuleSP dependency = all_modules.lookup(fs.GetPath())) {
3014+
scan_module(dependency, indent + 1);
3015+
} else if (ModuleSP dependency =
3016+
all_modules.lookup(fs.GetFilename())) {
3017+
scan_module(dependency, indent + 1);
3018+
} else {
3019+
if (GetLog(LLDBLog::Types)) {
3020+
std::string spacer(indent, '-');
3021+
LOG_PRINTF(GetLog(LLDBLog::Types),
3022+
"+%s Could not find %s in images", spacer.c_str(),
3023+
fs.GetPath().c_str());
3024+
}
3025+
}
3026+
}
3027+
}
3028+
};
3029+
scan_module(module_sp, 0);
3030+
for (size_t mi = 0; mi != num_images; ++mi) {
3031+
auto image_sp = target.GetImages().GetModuleAtIndex(mi);
3032+
if (!visited_modules.count(image_sp.get()))
3033+
swift_ast_sp->RegisterSectionModules(*image_sp, module_names);
29883034
}
29893035

29903036
LOG_PRINTF(GetLog(LLDBLog::Types), "((Target*)%p) = %p",
@@ -4372,6 +4418,7 @@ void SwiftASTContext::RegisterSectionModules(
43724418

43734419
// Grab all the AST blobs from the symbol vendor.
43744420
auto ast_file_datas = module.GetASTData(eLanguageTypeSwift);
4421+
if (ast_file_datas.size())
43754422
LOG_PRINTF(GetLog(LLDBLog::Types),
43764423
"(\"%s\") retrieved %zu AST Data blobs from the symbol vendor "
43774424
"(filter=\"%s\").",

lldb/test/API/lang/swift/deployment_target/TestSwiftDeploymentTarget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ def test_swift_deployment_target_from_macho(self):
6565
self.expect("expression f", substrs=["i = 23"])
6666
self.filecheck('platform shell cat ""%s"' % log, __file__)
6767
# CHECK: SwiftASTContextForExpressions::SetTriple({{.*}}apple-macosx11.0.0
68-
# CHECK: SwiftASTContextForExpressions::RegisterSectionModules("a.out") retrieved 0 AST Data blobs
68+
# CHECK-NOT: SwiftASTContextForExpressions::RegisterSectionModules("a.out"){{.*}} AST Data blobs

lldb/test/API/lang/swift/expression/import_search_paths/TestSwiftImportSearchPaths.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,19 @@ def do_test(self, flag):
3030
self, 'break here', lldb.SBFileSpec('main.swift'),
3131
extra_images=['Direct', self.getBuildArtifact('hidden/libIndirect')])
3232

33-
log = self.getBuildArtifact("types.log")
34-
self.expect('settings show '
35-
+ 'target.experimental')
36-
self.expect("log enable lldb types -f " + log)
33+
types_log = self.getBuildArtifact("types.log")
34+
self.expect("log enable lldb types -f " + types_log)
3735
self.expect("expr -- x.inner.hidden", substrs=['=', '42'])
38-
39-
import io, re
40-
logfile = io.open(log, "r", encoding='utf-8')
41-
sanity = 0
42-
found = 0
43-
for line in logfile:
44-
if re.match(r'.*SwiftASTContextForModule\("a\.out"\)::LogConfiguration\(\).*hidden$',
45-
line.strip('\n')):
46-
sanity += 1
47-
elif re.match(r'.*SwiftASTContextForExpressions::LogConfiguration\(\).*hidden$',
48-
line.strip('\n')):
49-
found += 1
50-
self.assertEqual(sanity, 1)
51-
self.assertEqual(found, 1 if flag == 'true' else 0)
36+
if flag == 'true':
37+
prefix = 'POSITIVE'
38+
else:
39+
prefix = 'NEGATIVE'
40+
self.filecheck('platform shell cat "%s"' % types_log, __file__,
41+
'--check-prefix=CHECK_MOD_'+prefix)
42+
self.filecheck('platform shell cat "%s"' % types_log, __file__,
43+
'--check-prefix=CHECK_EXP_'+prefix)
44+
# CHECK_MOD_POSITIVE: SwiftASTContextForModule("a.out")::LogConfiguration(){{.*hidden$}}
45+
# CHECK_MOD_NEGATIVE: SwiftASTContextForModule("a.out")::LogConfiguration(){{.*hidden$}}
46+
# CHECK_EXP_POSITIVE: SwiftASTContextForExpressions::LogConfiguration(){{.*hidden$}}
47+
# CHECK_EXP_NEGATIVE-NOT: SwiftASTContextForExpressions::LogConfiguration(){{.*hidden$}}
48+
# CHECK_EXP_NEGATIVE: SwiftASTContextForExpressions::LogConfiguration(){{.*}}Extra clang arguments

0 commit comments

Comments
 (0)