Skip to content

Avoid a false positive assertion error (NFC in NDEBUG) #2431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
2 changes: 2 additions & 0 deletions lldb/include/lldb/Target/SwiftLanguageRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class SwiftLanguageRuntime : public LanguageRuntime {

void ModulesDidLoad(const ModuleList &module_list) override;

bool IsSwiftRuntimeInitialized();

/// Mangling support.
/// \{
/// Use these passthrough functions rather than calling into Swift directly,
Expand Down
56 changes: 28 additions & 28 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,34 +890,34 @@ std::vector<ConstString> SwiftLanguage::GetPossibleFormattersMatches(
const bool check_cpp = false;
const bool check_objc = false;
bool canBeSwiftDynamic =
compiler_type.IsPossibleDynamicType(nullptr, check_cpp, check_objc) ||
// Foundation (but really any library) may create new
// Objective-C classes at runtime and LLDB's ObjC runtime
// implementation doesn't yet get notified about this. As a
// workaround we try to interpret ObjC id pointers as Swift
// classes to make them available.
(compiler_type.GetCanonicalType().GetTypeClass() ==
eTypeClassObjCObjectPointer);

if (canBeSwiftDynamic) {
do {
lldb::ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
break;
auto *runtime = SwiftLanguageRuntime::Get(process_sp);
if (runtime == nullptr)
break;
TypeAndOrName type_and_or_name;
Address address;
Value::ValueType value_type;
if (!runtime->GetDynamicTypeAndAddress(
valobj, use_dynamic, type_and_or_name, address, value_type))
break;
if (ConstString name = type_and_or_name.GetName())
result.push_back(name);
} while (false);
}

compiler_type.IsPossibleDynamicType(nullptr, check_cpp, check_objc);
// Foundation (but really any library) may create new
// Objective-C classes at runtime and LLDB's ObjC runtime
// implementation doesn't yet get notified about this. As a
// workaround we try to interpret ObjC id pointers as Swift
// classes to make them available.
bool canBeObjCSwiftType = (compiler_type.GetCanonicalType().GetTypeClass() ==
eTypeClassObjCObjectPointer);

if (!canBeSwiftDynamic && !canBeObjCSwiftType)
return result;
lldb::ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
return result;
auto *runtime = SwiftLanguageRuntime::Get(process_sp);
if (!runtime)
return result;
// If this condition fires, we're most likely in pure Objective-C program.
if (canBeObjCSwiftType && !runtime->IsSwiftRuntimeInitialized())
return result;
TypeAndOrName type_and_or_name;
Address address;
Value::ValueType value_type;
if (!runtime->GetDynamicTypeAndAddress(valobj, use_dynamic, type_and_or_name,
address, value_type))
return result;
if (ConstString name = type_and_or_name.GetName())
result.push_back(name);
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Target/SwiftLanguageRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ SwiftLanguageRuntime::SwiftLanguageRuntime(Process *process)
m_stub = std::make_unique<SwiftLanguageRuntimeStub>(*process);
}

bool SwiftLanguageRuntime::IsSwiftRuntimeInitialized() { return (bool)m_impl; }

void SwiftLanguageRuntime::ModulesDidLoad(const ModuleList &module_list) {
assert(m_process && "modules loaded without process");
if (m_impl) {
Expand Down