Skip to content
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
48 changes: 37 additions & 11 deletions lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,25 @@ GetObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) {
return obj_file_format;
}

static llvm::SmallVector<llvm::StringRef, 1>
GetLikelySwiftImageNamesForModule(ModuleSP module) {
if (!module || !module->GetFileSpec())
return {};

auto name =
module->GetFileSpec().GetFileNameStrippingExtension().GetStringRef();
if (name == "libswiftCore")
name = "Swift";
if (name.startswith("libswift"))
name = name.drop_front(8);
if (name.startswith("lib"))
name = name.drop_front(3);
return {name};
}

bool SwiftLanguageRuntimeImpl::AddJitObjectFileToReflectionContext(
ObjectFile &obj_file, llvm::Triple::ObjectFormatType obj_format_type) {
ObjectFile &obj_file, llvm::Triple::ObjectFormatType obj_format_type,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names) {
assert(obj_file.GetType() == ObjectFile::eTypeJIT &&
"Not a JIT object file!");
auto obj_file_format = GetObjectFileFormat(obj_format_type);
Expand All @@ -635,8 +652,7 @@ bool SwiftLanguageRuntimeImpl::AddJitObjectFileToReflectionContext(
return m_reflection_ctx->addImage(
[&](swift::ReflectionSectionKind section_kind)
-> std::pair<swift::remote::RemoteRef<void>, uint64_t> {
auto section_name =
obj_file_format->getSectionName(section_kind);
auto section_name = obj_file_format->getSectionName(section_kind);
for (auto section : *obj_file.GetSectionList()) {
JITSection *jit_section = llvm::dyn_cast<JITSection>(section.get());
if (jit_section && section->GetName().AsCString() == section_name) {
Expand All @@ -658,11 +674,13 @@ bool SwiftLanguageRuntimeImpl::AddJitObjectFileToReflectionContext(
}
}
return {};
});
},
likely_module_names);
}

bool SwiftLanguageRuntimeImpl::AddObjectFileToReflectionContext(
ModuleSP module) {
ModuleSP module,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names) {
auto obj_format_type =
module->GetArchitecture().GetTriple().getObjectFormat();

Expand Down Expand Up @@ -787,14 +805,16 @@ bool SwiftLanguageRuntimeImpl::AddObjectFileToReflectionContext(
}
return {};
};

return m_reflection_ctx->addImage(
[&](swift::ReflectionSectionKind section_kind)
-> std::pair<swift::remote::RemoteRef<void>, uint64_t> {
auto pair = find_section_with_kind(segment, section_kind);
if (pair.first)
return pair;
return find_section_with_kind(maybe_secondary_segment, section_kind);
});
},
likely_module_names);
}

bool SwiftLanguageRuntimeImpl::AddModuleToReflectionContext(
Expand All @@ -813,10 +833,12 @@ bool SwiftLanguageRuntimeImpl::AddModuleToReflectionContext(
Address start_address = obj_file->GetBaseAddress();
auto load_ptr = static_cast<uintptr_t>(
start_address.GetLoadAddress(&target));
auto likely_module_names = GetLikelySwiftImageNamesForModule(module_sp);
if (obj_file->GetType() == ObjectFile::eTypeJIT) {
auto object_format_type =
module_sp->GetArchitecture().GetTriple().getObjectFormat();
return AddJitObjectFileToReflectionContext(*obj_file, object_format_type);
return AddJitObjectFileToReflectionContext(*obj_file, object_format_type,
likely_module_names);
}

if (load_ptr == 0 || load_ptr == LLDB_INVALID_ADDRESS) {
Expand All @@ -843,13 +865,17 @@ bool SwiftLanguageRuntimeImpl::AddModuleToReflectionContext(
llvm::sys::MemoryBlock file_buffer((void *)file_data, size);
m_reflection_ctx->readELF(
swift::remote::RemoteAddress(load_ptr),
llvm::Optional<llvm::sys::MemoryBlock>(file_buffer));
llvm::Optional<llvm::sys::MemoryBlock>(file_buffer),
likely_module_names);
} else if (read_from_file_cache &&
obj_file->GetPluginName().equals("mach-o")) {
if (!AddObjectFileToReflectionContext(module_sp))
m_reflection_ctx->addImage(swift::remote::RemoteAddress(load_ptr));
if (!AddObjectFileToReflectionContext(module_sp, likely_module_names)) {
m_reflection_ctx->addImage(swift::remote::RemoteAddress(load_ptr),
likely_module_names);
}
} else {
m_reflection_ctx->addImage(swift::remote::RemoteAddress(load_ptr));
m_reflection_ctx->addImage(swift::remote::RemoteAddress(load_ptr),
likely_module_names);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,23 @@ class TargetReflectionContext
bool addImage(
llvm::function_ref<std::pair<swift::remote::RemoteRef<void>, uint64_t>(
swift::ReflectionSectionKind)>
find_section) override {
return m_reflection_ctx.addImage(find_section);
find_section,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names) override {
return m_reflection_ctx.addImage(find_section, likely_module_names);
}

bool addImage(swift::remote::RemoteAddress image_start) override {
return m_reflection_ctx.addImage(image_start);
bool
addImage(swift::remote::RemoteAddress image_start,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names) override {
return m_reflection_ctx.addImage(image_start, likely_module_names);
}

bool readELF(swift::remote::RemoteAddress ImageStart,
llvm::Optional<llvm::sys::MemoryBlock> FileBuffer) override {
return m_reflection_ctx.readELF(ImageStart, FileBuffer);
bool readELF(
swift::remote::RemoteAddress ImageStart,
llvm::Optional<llvm::sys::MemoryBlock> FileBuffer,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names = {}) override {
return m_reflection_ctx.readELF(ImageStart, FileBuffer,
likely_module_names);
}

const swift::reflection::TypeInfo *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,15 @@ class SwiftLanguageRuntimeImpl {
virtual bool addImage(
llvm::function_ref<std::pair<swift::remote::RemoteRef<void>, uint64_t>(
swift::ReflectionSectionKind)>
find_section) = 0;
virtual bool addImage(swift::remote::RemoteAddress image_start) = 0;
virtual bool readELF(swift::remote::RemoteAddress ImageStart,
llvm::Optional<llvm::sys::MemoryBlock> FileBuffer) = 0;
find_section,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names = {}) = 0;
virtual bool addImage(
swift::remote::RemoteAddress image_start,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names = {}) = 0;
virtual bool
readELF(swift::remote::RemoteAddress ImageStart,
llvm::Optional<llvm::sys::MemoryBlock> FileBuffer,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names = {}) = 0;
virtual const swift::reflection::TypeInfo *
getTypeInfo(const swift::reflection::TypeRef *type_ref,
swift::remote::TypeInfoProvider *provider) = 0;
Expand Down Expand Up @@ -388,13 +393,15 @@ class SwiftLanguageRuntimeImpl {
/// Add the contents of the object file to the reflection context.
/// \return true on success.
bool AddJitObjectFileToReflectionContext(
ObjectFile &obj_file, llvm::Triple::ObjectFormatType obj_format_type);
ObjectFile &obj_file, llvm::Triple::ObjectFormatType obj_format_type,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names);

/// Add the reflections sections to the reflection context by extracting
/// the directly from the object file.
/// \return true on success.
bool AddObjectFileToReflectionContext(
lldb::ModuleSP module);
lldb::ModuleSP module,
llvm::SmallVector<llvm::StringRef, 1> likely_module_names);

/// Cache for the debug-info-originating type infos.
/// \{
Expand Down