Skip to content

Commit 0baa1ac

Browse files
committed
[lldb] Wire up reflection support for Builtin.FixedArray
1 parent a00f97e commit 0baa1ac

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,22 @@ SwiftLanguageRuntime::GetNumChildren(CompilerType type,
833833
type.GetMangledTypeName().GetString());
834834
}
835835

836+
if (auto *ati = llvm::dyn_cast<swift::reflection::ArrayTypeInfo>(ti)) {
837+
LLDB_LOG(GetLog(LLDBLog::Types), "{0}: ArrayTypeInfo()",
838+
type.GetMangledTypeName().GetCString());
839+
auto *el_ti = ati->getElementTypeInfo();
840+
if (!el_ti)
841+
return llvm::createStringError("Array without element type info: " +
842+
type.GetMangledTypeName().GetString());
843+
// We could also get the value out of the mangled type name, but
844+
// this is cheaper.
845+
unsigned stride = el_ti->getStride();
846+
if (!stride)
847+
return llvm::createStringError("Array without element stride: " +
848+
type.GetMangledTypeName().GetString());
849+
return ati->getSize() / stride;
850+
}
851+
836852
LogUnimplementedTypeKind(__FUNCTION__, type);
837853
return llvm::createStringError("GetNumChildren unimplemented for type " +
838854
type.GetMangledTypeName().GetString());
@@ -1451,6 +1467,40 @@ llvm::Expected<CompilerType> SwiftLanguageRuntime::GetChildCompilerTypeAtIndex(
14511467
"is out of bounds (" + llvm::Twine(i - 1) +
14521468
")");
14531469
}
1470+
// Fixed array.
1471+
if (auto *ati = llvm::dyn_cast<swift::reflection::ArrayTypeInfo>(ti)) {
1472+
LLDB_LOG(GetLog(LLDBLog::Types), "{0}: ArrayTypeInfo()",
1473+
type.GetMangledTypeName().GetCString());
1474+
auto *el_ti = ati->getElementTypeInfo();
1475+
if (!el_ti)
1476+
return llvm::createStringError("array without element type info: " +
1477+
type.GetMangledTypeName().GetString());
1478+
child_name.clear();
1479+
llvm::raw_string_ostream(child_name) << idx;
1480+
child_byte_size = el_ti->getSize();
1481+
child_byte_offset = el_ti->getStride() * idx;
1482+
if (!ignore_array_bounds &&
1483+
(int64_t)child_byte_offset > (int64_t)ati->getSize())
1484+
return llvm::createStringError("array index out of bounds");
1485+
1486+
child_bitfield_bit_size = 0;
1487+
child_bitfield_bit_offset = 0;
1488+
child_is_base_class = false;
1489+
child_is_deref_of_parent = false;
1490+
language_flags = 0;
1491+
1492+
swift::Demangle::Demangler dem;
1493+
swift::Demangle::NodePointer global =
1494+
dem.demangleSymbol(type.GetMangledTypeName().GetStringRef());
1495+
using Kind = Node::Kind;
1496+
auto *dem_array_type = swift_demangle::ChildAtPath(
1497+
global, {Kind::TypeMangling, Kind::Type, Kind::BuiltinFixedArray});
1498+
if (!dem_array_type || dem_array_type->getNumChildren() != 2)
1499+
return llvm::createStringError("Expected fixed array, but found: " +
1500+
type.GetMangledTypeName().GetString());
1501+
return ts->RemangleAsType(dem, dem_array_type->getChild(1),
1502+
ts->GetManglingFlavor());
1503+
}
14541504
if (llvm::dyn_cast_or_null<swift::reflection::BuiltinTypeInfo>(ti)) {
14551505
// Clang enums have an artificial rawValue property. We could
14561506
// consider handling them here, but

lldb/test/API/lang/swift/value_generics/TestSwiftValueGenerics.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ class TestSwiftVariadicGenerics(TestBase):
1010
def test(self):
1111
self.build()
1212

13-
target, process, _, _ = lldbutil.run_to_source_breakpoint(
13+
target, process, thread, _ = lldbutil.run_to_source_breakpoint(
1414
self, "break here", lldb.SBFileSpec('main.swift'))
15-
self.expect('log enable lldb types')
16-
self.expect("frame variable v",
15+
self.expect("frame variable ints",
1716
substrs=["a.Vector<4, Int>", "storage",
18-
"0", "0",
19-
"1", "1",
20-
"2", "2",
21-
"3", "3"])
17+
"0", "1", "2", "3"])
18+
self.expect("frame variable bools",
19+
substrs=["a.Vector<2, Bool>", "storage",
20+
"false", "true"])
21+
self.expect("frame variable structs",
22+
substrs=["a.Vector<2, S>", "storage",
23+
"i", "1", "j", "2", "i", "3", "j", "4"])

lldb/test/API/lang/swift/value_generics/main.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,20 @@ extension Vector: Copyable where Element: Copyable {
3737
extension Vector: BitwiseCopyable where Element: BitwiseCopyable {}
3838

3939
func main() {
40-
var v = Vector<4, Int>(repeating: 0)
41-
v[0] = 0
42-
v[1] = 1
43-
v[2] = 2
44-
v[3] = 3
40+
var ints = Vector<4, Int>(repeating: 0)
41+
ints[0] = 0
42+
ints[1] = 1
43+
ints[2] = 2
44+
ints[3] = 3
45+
var bools = Vector<2, Bool>(repeating: false)
46+
bools[0] = false
47+
bools[1] = true
4548

46-
print(v) // break here
49+
struct S { let i : Int; let j : Int };
50+
var structs = Vector<2, S>(repeating: S(i: 1, j: 2))
51+
structs[0] = S(i: 1, j: 2)
52+
structs[1] = S(i: 3, j: 4)
53+
54+
print("\(ints), \(bools), \(structs)") // break here
4755
}
4856
main()

0 commit comments

Comments
 (0)