Skip to content
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
50 changes: 50 additions & 0 deletions lldb/source/Plugins/Language/Swift/FoundationValueTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/Status.h"
#include "lldb/ValueObject/ValueObject.h"
#include "lldb/lldb-enumerations.h"
Expand Down Expand Up @@ -419,6 +422,53 @@ bool lldb_private::formatters::swift::Data_SummaryProvider(
if (!success) {
return false;
}

// rdar://182785830 diagnostic. An inline Data can hold at most 14 bytes, so
// any larger `length` proves the reflection-derived layout of InlineData
// resolved the `length` field to the wrong offset/size. The canonical bad
// value is 197121 == 0x00030201 == the buffer bytes [1,2,3,0] read as a
// 4-byte int at offset 0. Dump the geometry so the failing CI run explains
// itself (part02 runs `log enable lldb types`, so this is captured).
if (count < 0 || count > 14) {
auto byte_size = [](const ValueObjectSP &v) -> uint64_t {
return llvm::expectedToStdOptional(v->GetByteSize()).value_or(0);
};
StreamString ss;
ss.Printf("[rdar182785830] IMPOSSIBLE inline length=%lld (cap 14). "
"length{type=%s, byte_size=%llu} "
"InlineData{byte_size=%llu, num_children=%u} children=[",
(long long)count,
length_sp->GetTypeName().AsCString("<null>"),
(unsigned long long)byte_size(length_sp),
(unsigned long long)byte_size(inline_data_sp),
inline_data_sp->GetNumChildrenIgnoringErrors());
for (uint32_t i = 0, e = inline_data_sp->GetNumChildrenIgnoringErrors();
i < e; ++i) {
ValueObjectSP c = inline_data_sp->GetChildAtIndex(i, true);
if (!c)
continue;
ss.Printf("%s%s:off=%llu:size=%llu", i ? ", " : "",
c->GetName().AsCString("<null>"),
(unsigned long long)c->GetByteOffset(),
(unsigned long long)byte_size(c));
}
ss.PutCString("] raw=");
DataExtractor bytes;
Status extract_err;
if (inline_data_sp->GetData(bytes, extract_err)) {
lldb::offset_t off = 0;
for (uint64_t i = 0; i < bytes.GetByteSize(); ++i)
ss.Printf("%02x ", bytes.GetU8(&off));
}
// Emit into BOTH the log and the summary itself. The summary is what
// dotest prints in the `expect` failure ("Got output: ..."), so this is
// guaranteed to reach the console when the test fails, without depending
// on a log channel being captured.
LLDB_LOG(GetLog(LLDBLog::DataFormatters | LLDBLog::Types), "{0}",
ss.GetString());
stream.PutCString(ss.GetString());
stream.PutCString(" ");
}
} else if (representation_case == g_slice) {
// Grab the associated value from `case slice(InlineSlice)`.
if (representation_enum_sp->GetNumChildrenIgnoringErrors() != 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,7 @@ llvm::Expected<CompilerType> SwiftLanguageRuntime::GetChildCompilerTypeAtIndex(
uint64_t &language_flags) {
CompilerType child_type;
bool found = false;
ConstString parent_mangled = type.GetMangledTypeName();
SwiftRuntimeTypeVisitor visitor(*this, type, valobj, omit_empty_base_classes);
llvm::Error error = visitor.VisitChildAtIndex(
idx,
Expand All @@ -1985,6 +1986,15 @@ llvm::Expected<CompilerType> SwiftLanguageRuntime::GetChildCompilerTypeAtIndex(
child_name = get_child_name();
child_byte_size = child.byte_size;
child_byte_offset = child.byte_offset;
// rdar://182785830: trace the geometry each field resolves to, so a
// wrong result for a resilient field (e.g. Data.InlineData.length
// resolving to offset 0 / size 4 instead of offset 14 / size 1) is
// visible in the types log at the exact moment of resolution.
LLDB_LOG(GetLog(LLDBLog::Types),
"[GetChildCompilerTypeAtIndex] {0} field #{1} '{2}' -> "
"byte_offset={3} byte_size={4}",
parent_mangled.GetStringRef(), (unsigned)idx,
child_name, child_byte_offset, child_byte_size);
child_bitfield_bit_size = child.bitfield_bit_size;
child_bitfield_bit_offset = child.bitfield_bit_offset;
child_is_base_class = child.is_base_class;
Expand Down
8 changes: 4 additions & 4 deletions lldb/test/API/lang/swift/array_tuple_resilient/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import Foundation
var patatino : [(Data, Int64)] = [(Data([1, 2, 3]), 1001)]
var tinky : [(Data, Data)] = [(Data([1, 2, 3]), Data([9]))]
print(patatino) //%self.expect('frame variable -d run -- patatino',
//% substrs=['byte', '1 = 1001'])
//% substrs=['0 = 3 bytes', '1 = 1001'])
//%self.expect('expr -d run -- patatino',
//% substrs=['byte', '1 = 1001'])
//% substrs=['0 = 3 bytes', '1 = 1001'])

print(tinky) //%self.expect('frame variable -d run -- tinky',
//% substrs=['byte'])
//% substrs=['0 = 3 bytes', '1 = 1 byte'])
//%self.expect('expr -d run -- tinky',
//% substrs=['byte'])
//% substrs=['0 = 3 bytes', '1 = 1 byte'])
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Auto-generated hammer shard for rdar://182785830 (flaky inline Data -> "197121
# bytes" instead of "3 bytes"). Independent, single-iteration copy of the
# explicit_modules part02 test_import check, so lit runs many in parallel to
# amplify attempts AND concurrent/CPU-starved load without any single test
# exceeding the 600s per-test timeout. Delete before merging.
import os
import shutil
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftDataHammer00(lldbtest.TestBase):

@skipEmbeddedSwift
@swiftTest
@skipUnlessDarwin
def test_import(self):
"""Repeat (via sharding) the flaky inline-Data resolution check."""
mod_cache = self.getBuildArtifact("my-clang-modules-cache")
if os.path.isdir(mod_cache):
shutil.rmtree(mod_cache)
self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
% mod_cache)

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))

self.expect('expression Data([1, 2, 3])', error=True)
self.expect("expression import Foundation")
self.expect('expression Data([1, 2, 3])', substrs=["3 bytes"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Auto-generated hammer shard for rdar://182785830 (flaky inline Data -> "197121
# bytes" instead of "3 bytes"). Independent, single-iteration copy of the
# explicit_modules part02 test_import check, so lit runs many in parallel to
# amplify attempts AND concurrent/CPU-starved load without any single test
# exceeding the 600s per-test timeout. Delete before merging.
import os
import shutil
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftDataHammer01(lldbtest.TestBase):

@skipEmbeddedSwift
@swiftTest
@skipUnlessDarwin
def test_import(self):
"""Repeat (via sharding) the flaky inline-Data resolution check."""
mod_cache = self.getBuildArtifact("my-clang-modules-cache")
if os.path.isdir(mod_cache):
shutil.rmtree(mod_cache)
self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
% mod_cache)

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))

self.expect('expression Data([1, 2, 3])', error=True)
self.expect("expression import Foundation")
self.expect('expression Data([1, 2, 3])', substrs=["3 bytes"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Auto-generated hammer shard for rdar://182785830 (flaky inline Data -> "197121
# bytes" instead of "3 bytes"). Independent, single-iteration copy of the
# explicit_modules part02 test_import check, so lit runs many in parallel to
# amplify attempts AND concurrent/CPU-starved load without any single test
# exceeding the 600s per-test timeout. Delete before merging.
import os
import shutil
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftDataHammer02(lldbtest.TestBase):

@skipEmbeddedSwift
@swiftTest
@skipUnlessDarwin
def test_import(self):
"""Repeat (via sharding) the flaky inline-Data resolution check."""
mod_cache = self.getBuildArtifact("my-clang-modules-cache")
if os.path.isdir(mod_cache):
shutil.rmtree(mod_cache)
self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
% mod_cache)

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))

self.expect('expression Data([1, 2, 3])', error=True)
self.expect("expression import Foundation")
self.expect('expression Data([1, 2, 3])', substrs=["3 bytes"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Auto-generated hammer shard for rdar://182785830 (flaky inline Data -> "197121
# bytes" instead of "3 bytes"). Independent, single-iteration copy of the
# explicit_modules part02 test_import check, so lit runs many in parallel to
# amplify attempts AND concurrent/CPU-starved load without any single test
# exceeding the 600s per-test timeout. Delete before merging.
import os
import shutil
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftDataHammer03(lldbtest.TestBase):

@skipEmbeddedSwift
@swiftTest
@skipUnlessDarwin
def test_import(self):
"""Repeat (via sharding) the flaky inline-Data resolution check."""
mod_cache = self.getBuildArtifact("my-clang-modules-cache")
if os.path.isdir(mod_cache):
shutil.rmtree(mod_cache)
self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
% mod_cache)

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))

self.expect('expression Data([1, 2, 3])', error=True)
self.expect("expression import Foundation")
self.expect('expression Data([1, 2, 3])', substrs=["3 bytes"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Auto-generated hammer shard for rdar://182785830 (flaky inline Data -> "197121
# bytes" instead of "3 bytes"). Independent, single-iteration copy of the
# explicit_modules part02 test_import check, so lit runs many in parallel to
# amplify attempts AND concurrent/CPU-starved load without any single test
# exceeding the 600s per-test timeout. Delete before merging.
import os
import shutil
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftDataHammer04(lldbtest.TestBase):

@skipEmbeddedSwift
@swiftTest
@skipUnlessDarwin
def test_import(self):
"""Repeat (via sharding) the flaky inline-Data resolution check."""
mod_cache = self.getBuildArtifact("my-clang-modules-cache")
if os.path.isdir(mod_cache):
shutil.rmtree(mod_cache)
self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
% mod_cache)

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))

self.expect('expression Data([1, 2, 3])', error=True)
self.expect("expression import Foundation")
self.expect('expression Data([1, 2, 3])', substrs=["3 bytes"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Auto-generated hammer shard for rdar://182785830 (flaky inline Data -> "197121
# bytes" instead of "3 bytes"). Independent, single-iteration copy of the
# explicit_modules part02 test_import check, so lit runs many in parallel to
# amplify attempts AND concurrent/CPU-starved load without any single test
# exceeding the 600s per-test timeout. Delete before merging.
import os
import shutil
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftDataHammer05(lldbtest.TestBase):

@skipEmbeddedSwift
@swiftTest
@skipUnlessDarwin
def test_import(self):
"""Repeat (via sharding) the flaky inline-Data resolution check."""
mod_cache = self.getBuildArtifact("my-clang-modules-cache")
if os.path.isdir(mod_cache):
shutil.rmtree(mod_cache)
self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
% mod_cache)

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))

self.expect('expression Data([1, 2, 3])', error=True)
self.expect("expression import Foundation")
self.expect('expression Data([1, 2, 3])', substrs=["3 bytes"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Auto-generated hammer shard for rdar://182785830 (flaky inline Data -> "197121
# bytes" instead of "3 bytes"). Independent, single-iteration copy of the
# explicit_modules part02 test_import check, so lit runs many in parallel to
# amplify attempts AND concurrent/CPU-starved load without any single test
# exceeding the 600s per-test timeout. Delete before merging.
import os
import shutil
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftDataHammer06(lldbtest.TestBase):

@skipEmbeddedSwift
@swiftTest
@skipUnlessDarwin
def test_import(self):
"""Repeat (via sharding) the flaky inline-Data resolution check."""
mod_cache = self.getBuildArtifact("my-clang-modules-cache")
if os.path.isdir(mod_cache):
shutil.rmtree(mod_cache)
self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
% mod_cache)

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))

self.expect('expression Data([1, 2, 3])', error=True)
self.expect("expression import Foundation")
self.expect('expression Data([1, 2, 3])', substrs=["3 bytes"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Auto-generated hammer shard for rdar://182785830 (flaky inline Data -> "197121
# bytes" instead of "3 bytes"). Independent, single-iteration copy of the
# explicit_modules part02 test_import check, so lit runs many in parallel to
# amplify attempts AND concurrent/CPU-starved load without any single test
# exceeding the 600s per-test timeout. Delete before merging.
import os
import shutil
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftDataHammer07(lldbtest.TestBase):

@skipEmbeddedSwift
@swiftTest
@skipUnlessDarwin
def test_import(self):
"""Repeat (via sharding) the flaky inline-Data resolution check."""
mod_cache = self.getBuildArtifact("my-clang-modules-cache")
if os.path.isdir(mod_cache):
shutil.rmtree(mod_cache)
self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
% mod_cache)

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))

self.expect('expression Data([1, 2, 3])', error=True)
self.expect("expression import Foundation")
self.expect('expression Data([1, 2, 3])', substrs=["3 bytes"])
Loading