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

Commit 38cebbf

Browse files
committed
Merge branch 'stable' of github.com:apple/swift-lldb into upstream-with-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
2 parents 86df4d5 + 4357a50 commit 38cebbf

File tree

11 files changed

+109
-47
lines changed

11 files changed

+109
-47
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module CModule {
22
header "c-header.h"
33
export *
4-
}
4+
module SubModule {
5+
header "submodule.h"
6+
export *
7+
}
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct FromSubmodule {
2+
unsigned x, y, z;
3+
};

packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/TestSwiftDWARFImporterC.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def build(self):
2626
inputs = self.getSourcePath('Inputs')
2727
lldbutil.mkdir_p(include)
2828
import shutil
29-
for f in ['module.modulemap', 'c-header.h']:
29+
for f in ['module.modulemap', 'c-header.h', 'submodule.h']:
3030
shutil.copyfile(os.path.join(inputs, f), os.path.join(include, f))
3131

3232
super(TestSwiftDWARFImporterC, self).build()
@@ -52,14 +52,17 @@ def test_dwarf_importer(self):
5252
lldbutil.check_variable(self,
5353
target.FindFirstGlobalVariable("point"),
5454
typename='__ObjC.Point', num_children=2)
55-
self.expect("fr v point", substrs=["x = 1", "y = 2"])
56-
self.expect("fr v point", substrs=["x = 1", "y = 2"])
57-
self.expect("fr v enumerator", substrs=[".yellow"])
58-
self.expect("fr v pureSwiftStruct", substrs=["pure swift"])
59-
self.expect("fr v swiftStructCMember",
60-
substrs=["x = 3", "y = 4", "swift struct c member"])
61-
self.expect("fr v typedef", substrs=["x = 5", "y = 6"])
62-
self.expect("fr v union", substrs=["(DoubleLongUnion)", "long_val = 42"])
55+
self.expect("ta v point", substrs=["x = 1", "y = 2"])
56+
self.expect("ta v enumerator", substrs=[".yellow"])
57+
self.expect("ta v pureSwiftStruct", substrs=["pure swift"])
58+
self.expect("ta v swiftStructCMember",
59+
substrs=["point", "x = 3", "y = 4",
60+
"sub", "x = 1", "y = 2", "z = 3",
61+
"swift struct c member"])
62+
self.expect("ta v typedef", substrs=["x = 5", "y = 6"])
63+
self.expect("ta v union", substrs=["(DoubleLongUnion)", "long_val = 42"])
64+
self.expect("ta v fromSubmodule",
65+
substrs=["(FromSubmodule)", "x = 1", "y = 2", "z = 3"])
6366
process.Clear()
6467
target.Clear()
6568
lldb.SBDebugger.MemoryPressureDetected()
@@ -79,7 +82,7 @@ def test_negative(self):
7982
lldbutil.check_variable(self,
8083
target.FindFirstGlobalVariable("point"),
8184
typename="Point", num_children=2)
82-
self.expect("fr v point", substrs=["x = 1", "y = 2"])
85+
self.expect("ta v point", substrs=["x = 1", "y = 2"])
8386

8487
found = False
8588
logfile = open(log, "r")

packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/main.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ let pureSwiftStruct = SwiftStruct()
1414

1515
struct SwiftStructCMember {
1616
let point = Point(x: 3, y: 4)
17+
let sub = FromSubmodule(x: 1, y: 2, z: 3)
1718
let name = "swift struct c member"
1819
}
1920

2021
let swiftStructCMember = SwiftStructCMember()
2122
let typedef = TPoint(x: 5, y: 6)
2223
let union = DoubleLongUnion(long_val: 42)
24+
let fromSubmodule = FromSubmodule(x: 1, y: 2, z: 3)
2325

2426
use(pureSwift) // break here
2527
use(point)
@@ -28,3 +30,4 @@ use(pureSwiftStruct)
2830
use(swiftStructCMember)
2931
use(typedef)
3032
use(union)
33+
use(fromSubmodule)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module ObjCModule {
22
header "objc-header.h"
33
export *
4-
}
4+
}

source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,18 @@ size_t SymbolFileDWARF::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
25352535
m_index->ReportInvalidDIERef(die_ref, name.GetStringRef());
25362536
}
25372537
}
2538+
2539+
// Next search through the reachable Clang modules. This only applies for
2540+
// DWARF objects compiled with -gmodules that haven't been processed by
2541+
// dsymutil.
2542+
UpdateExternalModuleListIfNeeded();
2543+
2544+
for (const auto &pair : m_external_type_modules)
2545+
if (ModuleSP external_module_sp = pair.second) {
2546+
SymbolVendor *sym_vendor = external_module_sp->GetSymbolVendor();
2547+
if (sym_vendor)
2548+
num_matches += sym_vendor->FindTypes(pattern, true, types);
2549+
}
25382550
return num_matches;
25392551
}
25402552

source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,22 @@ uint32_t SymbolFileDWARFDebugMap::FindTypes(
12121212
return types.GetSize() - initial_types_size;
12131213
}
12141214

1215+
size_t
1216+
SymbolFileDWARFDebugMap::FindTypes(llvm::ArrayRef<CompilerContext> context,
1217+
bool append, TypeMap &types) {
1218+
if (!append)
1219+
types.Clear();
1220+
1221+
const uint32_t initial_types_size = types.GetSize();
1222+
1223+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1224+
oso_dwarf->FindTypes(context, true, types);
1225+
return false;
1226+
});
1227+
1228+
return types.GetSize() - initial_types_size;
1229+
}
1230+
12151231
//
12161232
// uint32_t
12171233
// SymbolFileDWARFDebugMap::FindTypes (const SymbolContext& sc, const

source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
111111
bool append, uint32_t max_matches,
112112
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
113113
lldb_private::TypeMap &types) override;
114+
size_t FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> context,
115+
bool append, lldb_private::TypeMap &types) override;
114116
lldb_private::CompilerDeclContext FindNamespace(
115117
lldb_private::ConstString name,
116118
const lldb_private::CompilerDeclContext *parent_decl_ctx) override;

source/Symbol/LocateSymbolFileMacOSX.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,10 @@ bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
574574

575575
StreamString command;
576576
if (!uuid_str.empty())
577-
command.Printf("%s --ignoreNegativeCache --copyExecutable --databases "
578-
"bursar.apple.com,uuidsymmap.apple.com %s",
577+
command.Printf("%s --ignoreNegativeCache --copyExecutable %s",
579578
g_dsym_for_uuid_exe_path, uuid_str.c_str());
580579
else if (file_path[0] != '\0')
581-
command.Printf("%s --ignoreNegativeCache --copyExecutable --databases "
582-
"bursar.apple.com,uuidsymmap.apple.com %s",
580+
command.Printf("%s --ignoreNegativeCache --copyExecutable %s",
583581
g_dsym_for_uuid_exe_path, file_path);
584582

585583
if (!command.GetString().empty()) {

source/Symbol/SwiftASTContext.cpp

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,17 +3198,40 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
31983198
}
31993199
return nullptr;
32003200
}
3201+
3202+
static CompilerContextKind
3203+
GetCompilerContextKind(llvm::Optional<swift::ClangTypeKind> kind) {
3204+
if (!kind)
3205+
return CompilerContextKind::AnyType;
3206+
switch (*kind) {
3207+
case swift::ClangTypeKind::Typedef:
3208+
/*=swift::ClangTypeKind::ObjCClass:*/
3209+
return (CompilerContextKind)((uint16_t)CompilerContextKind::Any |
3210+
(uint16_t)CompilerContextKind::Typedef |
3211+
(uint16_t)CompilerContextKind::Struct);
3212+
break;
3213+
case swift::ClangTypeKind::Tag:
3214+
return (CompilerContextKind)((uint16_t)CompilerContextKind::Any |
3215+
(uint16_t)CompilerContextKind::Class |
3216+
(uint16_t)CompilerContextKind::Struct |
3217+
(uint16_t)CompilerContextKind::Union |
3218+
(uint16_t)CompilerContextKind::Enum);
3219+
// case swift::ClangTypeKind::ObjCProtocol:
3220+
// Not implemented since Objective-C protocols aren't yet
3221+
// described in DWARF.
3222+
default:
3223+
return CompilerContextKind::Invalid;
3224+
}
3225+
}
3226+
32013227

32023228
public:
32033229
SwiftDWARFImporterDelegate(SwiftASTContext &swift_ast_ctx)
32043230
: m_swift_ast_ctx(swift_ast_ctx) {}
32053231

3206-
void lookupValue(StringRef name,
3207-
llvm::Optional<swift::ClangTypeKind> kind,
3232+
void lookupValue(StringRef name, llvm::Optional<swift::ClangTypeKind> kind,
3233+
StringRef inModule,
32083234
llvm::SmallVectorImpl<clang::Decl *> &results) override {
3209-
std::vector<CompilerContext> decl_context;
3210-
ConstString name_cs(name);
3211-
decl_context.push_back({CompilerContextKind::Struct, name_cs});
32123235
auto clang_importer = m_swift_ast_ctx.GetClangImporter();
32133236
if (!clang_importer)
32143237
return;
@@ -3217,45 +3240,42 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
32173240
return;
32183241

32193242
// Find the type in the debug info.
3220-
TypeList clang_types;
3221-
const bool exact_match = true;
3222-
const uint32_t max_matches = UINT32_MAX;
3223-
llvm::DenseSet<SymbolFile *> searched_symbol_files;
3224-
if (!module->FindTypes(name_cs, exact_match, max_matches,
3225-
searched_symbol_files, clang_types))
3226-
return;
3243+
TypeMap clang_types;
3244+
3245+
llvm::SmallVector<CompilerContext, 3> decl_context;
3246+
// Perform a lookup in a specific module, if requested.
3247+
if (!inModule.empty())
3248+
decl_context.push_back(
3249+
{CompilerContextKind::Module, ConstString(inModule)});
3250+
// Swift doesn't keep track of submodules.
3251+
decl_context.push_back({CompilerContextKind::AnyModule, ConstString()});
3252+
decl_context.push_back({GetCompilerContextKind(kind), ConstString(name)});
3253+
module->GetSymbolVendor()->FindTypes(decl_context, true, clang_types);
32273254

3228-
SymbolFile *sym_file = m_swift_ast_ctx.GetSymbolFile();
3229-
if (!sym_file)
3230-
return;
3231-
auto ast_ctx = sym_file->GetTypeSystemForLanguage(eLanguageTypeObjC);
3232-
if (!ast_ctx)
3233-
return llvm::consumeError(ast_ctx.takeError());
3234-
auto *clang_ctx = llvm::dyn_cast_or_null<ClangASTContext>(&(*ast_ctx));
3235-
if (!clang_ctx)
3236-
return;
32373255
clang::FileSystemOptions file_system_options;
32383256
clang::FileManager file_manager(file_system_options);
3239-
for (unsigned i = 0; i < clang_types.GetSize(); ++i) {
3240-
TypeSP clang_type_sp = clang_types.GetTypeAtIndex(i);
3257+
clang_types.ForEach([&](lldb::TypeSP &clang_type_sp) {
32413258
if (!clang_type_sp)
3242-
continue;
3259+
return true;
32433260

32443261
// Filter out types with a mismatching type kind.
32453262
if (kind && HasTypeKind(clang_type_sp, *kind))
3246-
continue;
3263+
return true;
32473264

32483265
// Realize the full type.
32493266
CompilerType compiler_type = clang_type_sp->GetFullCompilerType();
3250-
// Import the type into the DWARFImporter's context.
3251-
clang::ASTContext &to_ctx = clang_importer->getClangASTContext();
3267+
3268+
// Filter our non-Clang types.
32523269
auto *type_system = llvm::dyn_cast_or_null<ClangASTContext>(
32533270
compiler_type.GetTypeSystem());
32543271
if (!type_system)
3255-
continue;
3272+
return true;
3273+
3274+
// Import the type into the DWARFImporter's context.
3275+
clang::ASTContext &to_ctx = clang_importer->getClangASTContext();
32563276
clang::ASTContext *from_ctx = type_system->getASTContext();
32573277
if (!from_ctx)
3258-
continue;
3278+
return true;
32593279
clang::ASTImporter importer(to_ctx, file_manager, *from_ctx, file_manager,
32603280
false);
32613281
llvm::Expected<clang::QualType> clang_type(
@@ -3277,7 +3297,8 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
32773297
if (clang::Decl *clang_decl = GetDeclForTypeAndKind(*clang_type, kind))
32783298
results.push_back(clang_decl);
32793299
}
3280-
}
3300+
return true;
3301+
});
32813302
}
32823303
};
32833304
} // namespace lldb_private

0 commit comments

Comments
 (0)