Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.
Closed
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
4 changes: 3 additions & 1 deletion include/lldb/Target/SwiftLanguageRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ class SwiftLanguageRuntime : public LanguageRuntime {
// to record useful runtime information
// This API's task is to strip those bits if necessary and return
// a pure pointer (or a tagged pointer)
lldb::addr_t MaybeMaskNonTrivialReferencePointer(lldb::addr_t);
lldb::addr_t MaybeMaskNonTrivialReferencePointer(
lldb::addr_t,
SwiftASTContext::NonTriviallyManagedReferenceStrategy strategy);

ConstString GetErrorBackstopName();

Expand Down
3 changes: 2 additions & 1 deletion source/Plugins/Language/Swift/SwiftOptional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ ExtractSomeIfAny(ValueObject *optional,
lldb::addr_t original_ptr =
value_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
lldb::addr_t tweaked_ptr =
swift_runtime->MaybeMaskNonTrivialReferencePointer(original_ptr);
swift_runtime->MaybeMaskNonTrivialReferencePointer(original_ptr,
strategy);
if (original_ptr != tweaked_ptr) {
CompilerType value_type(value_sp->GetCompilerType());
DataBufferSP buffer_sp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class AppleObjCRuntime : public lldb_private::ObjCLanguageRuntime {

virtual void GetValuesForGlobalCFBooleans(lldb::addr_t &cf_true,
lldb::addr_t &cf_false);

virtual bool IsTaggedPointer (lldb::addr_t addr) { return false; }

protected:
// Call CreateInstance instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {

EncodingToTypeSP GetEncodingToType() override;

bool IsTaggedPointer(lldb::addr_t ptr);
bool IsTaggedPointer(lldb::addr_t ptr) override;

TaggedPointerVendor *GetTaggedPointerVendor() override {
return m_tagged_pointer_vendor_ap.get();
Expand Down
89 changes: 79 additions & 10 deletions source/Target/SwiftLanguageRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3327,8 +3327,16 @@ SwiftLanguageRuntime::MaskMaybeBridgedPointer(lldb::addr_t addr,
}

lldb::addr_t
SwiftLanguageRuntime::MaybeMaskNonTrivialReferencePointer(lldb::addr_t addr) {
if (auto objc_runtime = GetObjCRuntime()) {
SwiftLanguageRuntime::MaybeMaskNonTrivialReferencePointer(
lldb::addr_t addr,
SwiftASTContext::NonTriviallyManagedReferenceStrategy strategy) {

if (addr == 0)
return addr;

AppleObjCRuntime *objc_runtime = GetObjCRuntime();

if (objc_runtime) {
// tagged pointers don't perform any masking
if (objc_runtime->IsTaggedPointer(addr))
return addr;
Expand Down Expand Up @@ -3372,16 +3380,77 @@ SwiftLanguageRuntime::MaybeMaskNonTrivialReferencePointer(lldb::addr_t addr) {

lldb::addr_t mask = 0;

if (is_arm && is_64)
mask = SWIFT_ABI_ARM64_OBJC_NUM_RESERVED_LOW_BITS;
else if (is_intel && is_64)
mask = SWIFT_ABI_X86_64_OBJC_NUM_RESERVED_LOW_BITS;
else
mask = SWIFT_ABI_DEFAULT_OBJC_NUM_RESERVED_LOW_BITS;
if (strategy == SwiftASTContext::NonTriviallyManagedReferenceStrategy::eWeak) {
bool is_indirect = true;

// On non-objc platforms, the weak reference pointer always pointed to a
// runtime structure.
// For ObjC platforms, the masked value determines whether it is indirect.

uint32_t value = 0;

if (objc_runtime)
{

if (is_intel) {
if (is_64) {
mask = SWIFT_ABI_X86_64_OBJC_WEAK_REFERENCE_MARKER_MASK;
value = SWIFT_ABI_X86_64_OBJC_WEAK_REFERENCE_MARKER_VALUE;
} else {
mask = SWIFT_ABI_I386_OBJC_WEAK_REFERENCE_MARKER_MASK;
value = SWIFT_ABI_I386_OBJC_WEAK_REFERENCE_MARKER_VALUE;
}
} else if (is_arm) {
if (is_64) {
mask = SWIFT_ABI_ARM64_OBJC_WEAK_REFERENCE_MARKER_MASK;
value = SWIFT_ABI_ARM64_OBJC_WEAK_REFERENCE_MARKER_VALUE;
} else {
mask = SWIFT_ABI_ARM_OBJC_WEAK_REFERENCE_MARKER_MASK;
value = SWIFT_ABI_ARM_OBJC_WEAK_REFERENCE_MARKER_VALUE;
}
}
} else {
// This name is a little confusing. The "DEFAULT" marking in System.h
// is supposed to mean: the value for non-ObjC platforms. So
// DEFAULT_OBJC here actually means "non-ObjC".
mask = SWIFT_ABI_DEFAULT_OBJC_WEAK_REFERENCE_MARKER_MASK;
value = SWIFT_ABI_DEFAULT_OBJC_WEAK_REFERENCE_MARKER_VALUE;
}

is_indirect = ((addr & mask) == value);

if (!is_indirect)
return addr;

// The masked value of address is a pointer to the runtime structure.
// The first field of the structure is the actual pointer.
Process *process = GetProcess();
Error error;

lldb::addr_t masked_addr = addr & ~mask;
lldb::addr_t isa_addr = process->ReadPointerFromMemory(masked_addr, error);
if (error.Fail())
{
// FIXME: do some logging here.
return addr;
}
return isa_addr;


} else {
if (is_arm && is_64)
mask = SWIFT_ABI_ARM64_OBJC_NUM_RESERVED_LOW_BITS;
else if (is_intel && is_64)
mask = SWIFT_ABI_X86_64_OBJC_NUM_RESERVED_LOW_BITS;
else
mask = SWIFT_ABI_DEFAULT_OBJC_NUM_RESERVED_LOW_BITS;

mask = (1 << mask) | (1 << (mask + 1));
mask = (1 << mask) | (1 << (mask + 1));

return addr & ~mask;
return addr & ~mask;
}

return addr;
}

ConstString SwiftLanguageRuntime::GetErrorBackstopName() {
Expand Down