diff --git a/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/Inputs/module.modulemap b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/Inputs/module.modulemap index 7356121d8134..822cd8009bcc 100644 --- a/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/Inputs/module.modulemap +++ b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/Inputs/module.modulemap @@ -1,4 +1,8 @@ module CModule { header "c-header.h" export * -} \ No newline at end of file + module SubModule { + header "submodule.h" + export * + } +} diff --git a/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/Inputs/submodule.h b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/Inputs/submodule.h new file mode 100644 index 000000000000..4f1840af805a --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/Inputs/submodule.h @@ -0,0 +1,3 @@ +struct FromSubmodule { + unsigned x, y, z; +}; diff --git a/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/TestSwiftDWARFImporterC.py b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/TestSwiftDWARFImporterC.py index ee3eb8c14eae..459d1c594188 100644 --- a/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/TestSwiftDWARFImporterC.py +++ b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/TestSwiftDWARFImporterC.py @@ -26,7 +26,7 @@ def build(self): inputs = self.getSourcePath('Inputs') lldbutil.mkdir_p(include) import shutil - for f in ['module.modulemap', 'c-header.h']: + for f in ['module.modulemap', 'c-header.h', 'submodule.h']: shutil.copyfile(os.path.join(inputs, f), os.path.join(include, f)) super(TestSwiftDWARFImporterC, self).build() @@ -52,14 +52,17 @@ def test_dwarf_importer(self): lldbutil.check_variable(self, target.FindFirstGlobalVariable("point"), typename='__ObjC.Point', num_children=2) - self.expect("fr v point", substrs=["x = 1", "y = 2"]) - self.expect("fr v point", substrs=["x = 1", "y = 2"]) - self.expect("fr v enumerator", substrs=[".yellow"]) - self.expect("fr v pureSwiftStruct", substrs=["pure swift"]) - self.expect("fr v swiftStructCMember", - substrs=["x = 3", "y = 4", "swift struct c member"]) - self.expect("fr v typedef", substrs=["x = 5", "y = 6"]) - self.expect("fr v union", substrs=["(DoubleLongUnion)", "long_val = 42"]) + self.expect("ta v point", substrs=["x = 1", "y = 2"]) + self.expect("ta v enumerator", substrs=[".yellow"]) + self.expect("ta v pureSwiftStruct", substrs=["pure swift"]) + self.expect("ta v swiftStructCMember", + substrs=["point", "x = 3", "y = 4", + "sub", "x = 1", "y = 2", "z = 3", + "swift struct c member"]) + self.expect("ta v typedef", substrs=["x = 5", "y = 6"]) + self.expect("ta v union", substrs=["(DoubleLongUnion)", "long_val = 42"]) + self.expect("ta v fromSubmodule", + substrs=["(FromSubmodule)", "x = 1", "y = 2", "z = 3"]) process.Clear() target.Clear() lldb.SBDebugger.MemoryPressureDetected() @@ -79,7 +82,7 @@ def test_negative(self): lldbutil.check_variable(self, target.FindFirstGlobalVariable("point"), typename="Point", num_children=2) - self.expect("fr v point", substrs=["x = 1", "y = 2"]) + self.expect("ta v point", substrs=["x = 1", "y = 2"]) found = False logfile = open(log, "r") diff --git a/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/main.swift b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/main.swift index 2ea1f732fe6b..45ac92a6b7b0 100644 --- a/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/main.swift +++ b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/main.swift @@ -14,12 +14,14 @@ let pureSwiftStruct = SwiftStruct() struct SwiftStructCMember { let point = Point(x: 3, y: 4) + let sub = FromSubmodule(x: 1, y: 2, z: 3) let name = "swift struct c member" } let swiftStructCMember = SwiftStructCMember() let typedef = TPoint(x: 5, y: 6) let union = DoubleLongUnion(long_val: 42) +let fromSubmodule = FromSubmodule(x: 1, y: 2, z: 3) use(pureSwift) // break here use(point) @@ -28,3 +30,4 @@ use(pureSwiftStruct) use(swiftStructCMember) use(typedef) use(union) +use(fromSubmodule) diff --git a/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/Objective-C/Inputs/module.modulemap b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/Objective-C/Inputs/module.modulemap index a9ef2ed15c11..2f37bc7aad4f 100644 --- a/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/Objective-C/Inputs/module.modulemap +++ b/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/Objective-C/Inputs/module.modulemap @@ -1,4 +1,4 @@ module ObjCModule { header "objc-header.h" export * -} \ No newline at end of file +} diff --git a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index b0173489d74a..f8cf44e34bb5 100644 --- a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2535,6 +2535,18 @@ size_t SymbolFileDWARF::FindTypes(llvm::ArrayRef pattern, m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); } } + + // Next search through the reachable Clang modules. This only applies for + // DWARF objects compiled with -gmodules that haven't been processed by + // dsymutil. + UpdateExternalModuleListIfNeeded(); + + for (const auto &pair : m_external_type_modules) + if (ModuleSP external_module_sp = pair.second) { + SymbolVendor *sym_vendor = external_module_sp->GetSymbolVendor(); + if (sym_vendor) + num_matches += sym_vendor->FindTypes(pattern, true, types); + } return num_matches; } diff --git a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index 68a56de0ff86..40eeb8963d94 100644 --- a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -1212,6 +1212,22 @@ uint32_t SymbolFileDWARFDebugMap::FindTypes( return types.GetSize() - initial_types_size; } +size_t +SymbolFileDWARFDebugMap::FindTypes(llvm::ArrayRef context, + bool append, TypeMap &types) { + if (!append) + types.Clear(); + + const uint32_t initial_types_size = types.GetSize(); + + ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { + oso_dwarf->FindTypes(context, true, types); + return false; + }); + + return types.GetSize() - initial_types_size; +} + // // uint32_t // SymbolFileDWARFDebugMap::FindTypes (const SymbolContext& sc, const diff --git a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h index d92153cc59ce..946af1f22f9b 100644 --- a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h +++ b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h @@ -111,6 +111,8 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile { bool append, uint32_t max_matches, llvm::DenseSet &searched_symbol_files, lldb_private::TypeMap &types) override; + size_t FindTypes(llvm::ArrayRef context, + bool append, lldb_private::TypeMap &types) override; lldb_private::CompilerDeclContext FindNamespace( lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx) override; diff --git a/source/Symbol/LocateSymbolFileMacOSX.cpp b/source/Symbol/LocateSymbolFileMacOSX.cpp index e98c36bdd77b..8b56fcc18cc0 100644 --- a/source/Symbol/LocateSymbolFileMacOSX.cpp +++ b/source/Symbol/LocateSymbolFileMacOSX.cpp @@ -574,12 +574,10 @@ bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec, StreamString command; if (!uuid_str.empty()) - command.Printf("%s --ignoreNegativeCache --copyExecutable --databases " - "bursar.apple.com,uuidsymmap.apple.com %s", + command.Printf("%s --ignoreNegativeCache --copyExecutable %s", g_dsym_for_uuid_exe_path, uuid_str.c_str()); else if (file_path[0] != '\0') - command.Printf("%s --ignoreNegativeCache --copyExecutable --databases " - "bursar.apple.com,uuidsymmap.apple.com %s", + command.Printf("%s --ignoreNegativeCache --copyExecutable %s", g_dsym_for_uuid_exe_path, file_path); if (!command.GetString().empty()) { diff --git a/source/Symbol/SwiftASTContext.cpp b/source/Symbol/SwiftASTContext.cpp index 0d0c41a0bb76..c3fdea21537a 100644 --- a/source/Symbol/SwiftASTContext.cpp +++ b/source/Symbol/SwiftASTContext.cpp @@ -3198,17 +3198,40 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate { } return nullptr; } + + static CompilerContextKind + GetCompilerContextKind(llvm::Optional kind) { + if (!kind) + return CompilerContextKind::AnyType; + switch (*kind) { + case swift::ClangTypeKind::Typedef: + /*=swift::ClangTypeKind::ObjCClass:*/ + return (CompilerContextKind)((uint16_t)CompilerContextKind::Any | + (uint16_t)CompilerContextKind::Typedef | + (uint16_t)CompilerContextKind::Struct); + break; + case swift::ClangTypeKind::Tag: + return (CompilerContextKind)((uint16_t)CompilerContextKind::Any | + (uint16_t)CompilerContextKind::Class | + (uint16_t)CompilerContextKind::Struct | + (uint16_t)CompilerContextKind::Union | + (uint16_t)CompilerContextKind::Enum); + // case swift::ClangTypeKind::ObjCProtocol: + // Not implemented since Objective-C protocols aren't yet + // described in DWARF. + default: + return CompilerContextKind::Invalid; + } + } + public: SwiftDWARFImporterDelegate(SwiftASTContext &swift_ast_ctx) : m_swift_ast_ctx(swift_ast_ctx) {} - void lookupValue(StringRef name, - llvm::Optional kind, + void lookupValue(StringRef name, llvm::Optional kind, + StringRef inModule, llvm::SmallVectorImpl &results) override { - std::vector decl_context; - ConstString name_cs(name); - decl_context.push_back({CompilerContextKind::Struct, name_cs}); auto clang_importer = m_swift_ast_ctx.GetClangImporter(); if (!clang_importer) return; @@ -3217,45 +3240,42 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate { return; // Find the type in the debug info. - TypeList clang_types; - const bool exact_match = true; - const uint32_t max_matches = UINT32_MAX; - llvm::DenseSet searched_symbol_files; - if (!module->FindTypes(name_cs, exact_match, max_matches, - searched_symbol_files, clang_types)) - return; + TypeMap clang_types; + + llvm::SmallVector decl_context; + // Perform a lookup in a specific module, if requested. + if (!inModule.empty()) + decl_context.push_back( + {CompilerContextKind::Module, ConstString(inModule)}); + // Swift doesn't keep track of submodules. + decl_context.push_back({CompilerContextKind::AnyModule, ConstString()}); + decl_context.push_back({GetCompilerContextKind(kind), ConstString(name)}); + module->GetSymbolVendor()->FindTypes(decl_context, true, clang_types); - SymbolFile *sym_file = m_swift_ast_ctx.GetSymbolFile(); - if (!sym_file) - return; - auto ast_ctx = sym_file->GetTypeSystemForLanguage(eLanguageTypeObjC); - if (!ast_ctx) - return llvm::consumeError(ast_ctx.takeError()); - auto *clang_ctx = llvm::dyn_cast_or_null(&(*ast_ctx)); - if (!clang_ctx) - return; clang::FileSystemOptions file_system_options; clang::FileManager file_manager(file_system_options); - for (unsigned i = 0; i < clang_types.GetSize(); ++i) { - TypeSP clang_type_sp = clang_types.GetTypeAtIndex(i); + clang_types.ForEach([&](lldb::TypeSP &clang_type_sp) { if (!clang_type_sp) - continue; + return true; // Filter out types with a mismatching type kind. if (kind && HasTypeKind(clang_type_sp, *kind)) - continue; + return true; // Realize the full type. CompilerType compiler_type = clang_type_sp->GetFullCompilerType(); - // Import the type into the DWARFImporter's context. - clang::ASTContext &to_ctx = clang_importer->getClangASTContext(); + + // Filter our non-Clang types. auto *type_system = llvm::dyn_cast_or_null( compiler_type.GetTypeSystem()); if (!type_system) - continue; + return true; + + // Import the type into the DWARFImporter's context. + clang::ASTContext &to_ctx = clang_importer->getClangASTContext(); clang::ASTContext *from_ctx = type_system->getASTContext(); if (!from_ctx) - continue; + return true; clang::ASTImporter importer(to_ctx, file_manager, *from_ctx, file_manager, false); llvm::Expected clang_type( @@ -3277,7 +3297,8 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate { if (clang::Decl *clang_decl = GetDeclForTypeAndKind(*clang_type, kind)) results.push_back(clang_decl); } - } + return true; + }); } }; } // namespace lldb_private diff --git a/tools/lldb-test/lldb-test.cpp b/tools/lldb-test/lldb-test.cpp index d7b67373e5ea..5eaf006d1285 100644 --- a/tools/lldb-test/lldb-test.cpp +++ b/tools/lldb-test/lldb-test.cpp @@ -513,7 +513,7 @@ Error opts::symbols::findTypes(lldb_private::Module &Module) { Symfile.FindTypes(ConstString(Name), ContextPtr, true, UINT32_MAX, SearchedFiles, Map); else - Symfile.FindTypes({parseCompilerContext()}, true, Map); + Symfile.FindTypes(parseCompilerContext(), true, Map); outs() << formatv("Found {0} types:\n", Map.GetSize()); StreamString Stream;