Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Merge branch 'stable' of github.com:apple/swift-lldb into upstream-wi…
Browse files Browse the repository at this point in the history
…th-swift

 Conflicts:
	include/lldb/Symbol/SymbolVendor.h
	include/lldb/lldb-private-enumerations.h
	source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
	source/Symbol/SwiftASTContext.cpp
	source/Symbol/SymbolVendor.cpp
	tools/lldb-test/lldb-test.cpp
  • Loading branch information
adrian-prantl committed Aug 22, 2019
2 parents 86df4d5 + 4357a50 commit 38cebbf
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module CModule {
header "c-header.h"
export *
}
module SubModule {
header "submodule.h"
export *
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct FromSubmodule {
unsigned x, y, z;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,3 +30,4 @@ use(pureSwiftStruct)
use(swiftStructCMember)
use(typedef)
use(union)
use(fromSubmodule)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ObjCModule {
header "objc-header.h"
export *
}
}
12 changes: 12 additions & 0 deletions source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,18 @@ size_t SymbolFileDWARF::FindTypes(llvm::ArrayRef<CompilerContext> 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;
}

Expand Down
16 changes: 16 additions & 0 deletions source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,22 @@ uint32_t SymbolFileDWARFDebugMap::FindTypes(
return types.GetSize() - initial_types_size;
}

size_t
SymbolFileDWARFDebugMap::FindTypes(llvm::ArrayRef<CompilerContext> 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
Expand Down
2 changes: 2 additions & 0 deletions source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
bool append, uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
lldb_private::TypeMap &types) override;
size_t FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> context,
bool append, lldb_private::TypeMap &types) override;
lldb_private::CompilerDeclContext FindNamespace(
lldb_private::ConstString name,
const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
Expand Down
6 changes: 2 additions & 4 deletions source/Symbol/LocateSymbolFileMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
81 changes: 51 additions & 30 deletions source/Symbol/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3198,17 +3198,40 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
}
return nullptr;
}

static CompilerContextKind
GetCompilerContextKind(llvm::Optional<swift::ClangTypeKind> 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<swift::ClangTypeKind> kind,
void lookupValue(StringRef name, llvm::Optional<swift::ClangTypeKind> kind,
StringRef inModule,
llvm::SmallVectorImpl<clang::Decl *> &results) override {
std::vector<CompilerContext> 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;
Expand All @@ -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<SymbolFile *> searched_symbol_files;
if (!module->FindTypes(name_cs, exact_match, max_matches,
searched_symbol_files, clang_types))
return;
TypeMap clang_types;

llvm::SmallVector<CompilerContext, 3> 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<ClangASTContext>(&(*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<ClangASTContext>(
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::QualType> clang_type(
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/lldb-test/lldb-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 38cebbf

Please sign in to comment.