@@ -1764,50 +1764,33 @@ CreatePackType(swift::Demangle::Demangler &dem, TypeSystemSwiftTypeRef &ts,
1764
1764
return pack;
1765
1765
}
1766
1766
1767
- bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack (
1768
- ValueObject &in_value, CompilerType pack_type,
1769
- lldb::DynamicValueType use_dynamic, TypeAndOrName &pack_type_or_name,
1770
- Address &address, Value::ValueType &value_type) {
1771
- Log *log (GetLog (LLDBLog::Types));
1767
+ llvm::Expected<CompilerType>
1768
+ SwiftLanguageRuntime::BindGenericPackType (StackFrame &frame,
1769
+ CompilerType pack_type, bool *is_indirect) {
1770
+ swift::Demangle::Demangler dem;
1771
+ Target &target = GetProcess ().GetTarget ();
1772
+ size_t ptr_size = GetProcess ().GetAddressByteSize ();
1773
+ ConstString func_name = frame.GetSymbolContext (eSymbolContextFunction)
1774
+ .GetFunctionName (Mangled::ePreferMangled);
1772
1775
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
1773
1776
if (!reflection_ctx)
1774
- return false ;
1775
-
1776
- // Return a tuple type, with one element per pack element and its
1777
- // type has all DependentGenericParamType that appear in type packs
1778
- // substituted.
1779
-
1780
- StackFrameSP frame = in_value.GetExecutionContextRef ().GetFrameSP ();
1781
- if (!frame)
1782
- return false ;
1783
- ConstString func_name = frame->GetSymbolContext (eSymbolContextFunction)
1784
- .GetFunctionName (Mangled::ePreferMangled);
1777
+ return llvm::createStringError (" no reflection context" );
1785
1778
1786
1779
// Extract the generic signature from the function symbol.
1787
1780
auto ts =
1788
1781
pack_type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwiftTypeRef>();
1789
1782
if (!ts)
1790
- return false ;
1783
+ return llvm::createStringError ( " no type system " ) ;
1791
1784
auto signature =
1792
- SwiftLanguageRuntime::GetGenericSignature (func_name.GetStringRef (), *ts);
1793
- if (!signature) {
1794
- LLDB_LOG (log, " cannot decode pack_expansion type: failed to decode generic "
1795
- " signature from function name" );
1796
- return false ;
1797
- }
1798
- // This type has already been resolved?
1799
- if (auto info = ts->IsSILPackType (pack_type))
1800
- if (info->expanded )
1801
- return false ;
1802
-
1803
- Target &target = GetProcess ().GetTarget ();
1804
- size_t ptr_size = GetProcess ().GetAddressByteSize ();
1805
-
1806
- swift::Demangle::Demangler dem;
1785
+ SwiftLanguageRuntime::GetGenericSignature (func_name.GetStringRef (), *ts);
1786
+ if (!signature)
1787
+ return llvm::createStringError (
1788
+ " cannot decode pack_expansion type: failed to decode generic signature "
1789
+ " from function name" );
1807
1790
1808
1791
auto expand_pack_type = [&](ConstString mangled_pack_type, bool indirect,
1809
1792
swift::Mangle::ManglingFlavor flavor)
1810
- -> swift::Demangle::NodePointer {
1793
+ -> llvm::Expected< swift::Demangle::NodePointer> {
1811
1794
// Find pack_type in the pack_expansions.
1812
1795
unsigned i = 0 ;
1813
1796
SwiftLanguageRuntime::GenericSignature::PackExpansion *pack_expansion =
@@ -1819,26 +1802,23 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack(
1819
1802
}
1820
1803
++i;
1821
1804
}
1822
- if (!pack_expansion) {
1823
- LLDB_LOG (log, " cannot decode pack_expansion type: failed to find a "
1824
- " matching type in the function signature" );
1825
- return {};
1826
- }
1805
+ if (!pack_expansion)
1806
+ return llvm::createStringError (
1807
+ " cannot decode pack_expansion type: failed to find a matching type "
1808
+ " in the function signature" );
1827
1809
1828
1810
// Extract the count.
1829
1811
llvm::SmallString<16 > buf;
1830
1812
llvm::raw_svector_ostream os (buf);
1831
1813
os << " $pack_count_" << signature->GetCountForValuePack (i);
1832
1814
StringRef count_var = os.str ();
1833
1815
std::optional<lldb::addr_t > count =
1834
- GetTypeMetadataForTypeNameAndFrame (count_var, *frame);
1835
- if (!count) {
1836
- LLDB_LOG (log,
1837
- " cannot decode pack_expansion type: failed to find count "
1838
- " argument \" %s\" in frame" ,
1839
- count_var.str ());
1840
- return {};
1841
- }
1816
+ GetTypeMetadataForTypeNameAndFrame (count_var, frame);
1817
+ if (!count)
1818
+ return llvm::createStringError (
1819
+ " cannot decode pack_expansion type: failed to find count argument "
1820
+ " \" %s\" in frame" ,
1821
+ count_var.str ().c_str ());
1842
1822
1843
1823
// Extract the metadata for the type packs in this value pack.
1844
1824
llvm::SmallDenseMap<std::pair<unsigned , unsigned >, lldb::addr_t > type_packs;
@@ -1861,13 +1841,13 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack(
1861
1841
os << u8" $\u03C4 _" << shape.depth << ' _' << shape.index ;
1862
1842
StringRef mds_var = os.str ();
1863
1843
std::optional<lldb::addr_t > mds_ptr =
1864
- GetTypeMetadataForTypeNameAndFrame (mds_var, * frame);
1844
+ GetTypeMetadataForTypeNameAndFrame (mds_var, frame);
1865
1845
if (!mds_ptr) {
1866
- LLDB_LOG (log ,
1867
- " cannot decode pack_expansion type: failed to find "
1868
- " metadata "
1869
- " for \" {0}\" in frame" ,
1870
- mds_var.str ());
1846
+ LLDB_LOG (GetLog (LLDBLog::Types) ,
1847
+ " cannot decode pack_expansion type: failed to find "
1848
+ " metadata "
1849
+ " for \" {0}\" in frame" ,
1850
+ mds_var.str ());
1871
1851
error = true ;
1872
1852
return ;
1873
1853
}
@@ -1876,7 +1856,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack(
1876
1856
}
1877
1857
});
1878
1858
if (error)
1879
- return {} ;
1859
+ return llvm::createStringError ( " cannot decode pack_expansion type " ) ;
1880
1860
1881
1861
// Walk the type packs.
1882
1862
std::vector<TypeSystemSwift::TupleElement> elements;
@@ -1893,29 +1873,25 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack(
1893
1873
Status status;
1894
1874
lldb::addr_t md = LLDB_INVALID_ADDRESS;
1895
1875
target.ReadMemory (md_ptr, &md, ptr_size, status, true );
1896
- if (!status.Success ()) {
1897
- LLDB_LOGF (log,
1876
+ if (!status.Success ())
1877
+ return llvm::createStringError (
1898
1878
" cannot decode pack_expansion type: failed to read type "
1899
1879
" pack for type %d/%d of type pack with shape %d %d" ,
1900
1880
j, (unsigned )*count, depth, index);
1901
- return {};
1902
- }
1903
1881
1904
1882
auto type_ref_or_err =
1905
1883
reflection_ctx->ReadTypeFromMetadata (md, ts->GetDescriptorFinder ());
1906
- if (!type_ref_or_err) {
1907
- LLDB_LOG_ERRORV (GetLog (LLDBLog::Types), type_ref_or_err.takeError (),
1908
- " {0}" );
1909
- LLDB_LOGF (log,
1910
- " cannot decode pack_expansion type: failed to decode type "
1911
- " metadata for type %d/%d of type pack with shape %d %d" ,
1912
- j, (unsigned )*count, depth, index);
1913
- return {};
1914
- }
1884
+ if (!type_ref_or_err)
1885
+ return llvm::joinErrors (
1886
+ llvm::createStringError (
1887
+ " cannot decode pack_expansion type: failed to decode type "
1888
+ " metadata for type %d/%d of type pack with shape %d %d" ,
1889
+ j, (unsigned )*count, depth, index),
1890
+ type_ref_or_err.takeError ());
1915
1891
substitutions.insert ({{depth, index}, &*type_ref_or_err});
1916
1892
}
1917
1893
if (substitutions.empty ())
1918
- return {} ;
1894
+ return llvm::createStringError ( " found no substitutions " ) ;
1919
1895
1920
1896
// Replace all pack expansions with a singular type. Otherwise the
1921
1897
// reflection context won't accept them.
@@ -1932,21 +1908,15 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack(
1932
1908
// Build a TypeRef from the demangle tree.
1933
1909
auto type_ref_or_err = reflection_ctx->GetTypeRef (
1934
1910
dem, pack_element, ts->GetDescriptorFinder ());
1935
- if (!type_ref_or_err) {
1936
- LLDB_LOG_ERRORV (GetLog (LLDBLog::Types), type_ref_or_err.takeError (),
1937
- " {0}" );
1938
- return {};
1939
- }
1911
+ if (!type_ref_or_err)
1912
+ return type_ref_or_err.takeError ();
1940
1913
auto &type_ref = *type_ref_or_err;
1941
1914
1942
1915
// Apply the substitutions.
1943
1916
auto bound_typeref_or_err = reflection_ctx->ApplySubstitutions (
1944
1917
type_ref, substitutions, ts->GetDescriptorFinder ());
1945
- if (!bound_typeref_or_err) {
1946
- LLDB_LOG_ERRORV (GetLog (LLDBLog::Types), bound_typeref_or_err.takeError (),
1947
- " {0}" );
1948
- return {};
1949
- }
1918
+ if (!bound_typeref_or_err)
1919
+ return bound_typeref_or_err.takeError ();
1950
1920
swift::Demangle::NodePointer node = bound_typeref_or_err->getDemangling (dem);
1951
1921
CompilerType type = ts->RemangleAsType (dem, node, flavor);
1952
1922
@@ -1976,12 +1946,14 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack(
1976
1946
1977
1947
auto flavor =
1978
1948
SwiftLanguageRuntime::GetManglingFlavor (pack_type.GetMangledTypeName ());
1949
+ bool indirect = false ;
1979
1950
1980
1951
// Expand all the pack types that appear in the incoming type,
1981
1952
// either at the root level or as arguments of bound generic types.
1982
- bool indirect = false ;
1983
- auto transformed = TypeSystemSwiftTypeRef::Transform (
1984
- dem, node, [&](swift::Demangle::NodePointer node) {
1953
+ auto transformed = TypeSystemSwiftTypeRef::TryTransform (
1954
+ dem, node,
1955
+ [&](swift::Demangle::NodePointer node)
1956
+ -> llvm::Expected<swift::Demangle::NodePointer> {
1985
1957
if (node->getKind () == swift::Demangle::Node::Kind::SILPackIndirect)
1986
1958
indirect = true ;
1987
1959
if (node->getKind () != swift::Demangle::Node::Kind::SILPackIndirect &&
@@ -1994,17 +1966,48 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack(
1994
1966
node = node->getChild (0 );
1995
1967
CompilerType pack_type = ts->RemangleAsType (dem, node, flavor);
1996
1968
ConstString mangled_pack_type = pack_type.GetMangledTypeName ();
1997
- LLDB_LOG (log, " decoded pack_expansion type: {0}" , mangled_pack_type);
1998
- auto result = expand_pack_type (mangled_pack_type, indirect, flavor);
1999
- if (!result) {
2000
- LLDB_LOG (log, " failed to expand pack type: {0}" , mangled_pack_type);
2001
- return node;
2002
- }
2003
- return result;
1969
+ LLDB_LOG (GetLog (LLDBLog::Types), " decoded pack_expansion type: {0}" ,
1970
+ mangled_pack_type);
1971
+ return expand_pack_type (mangled_pack_type, indirect, flavor);
2004
1972
});
2005
1973
2006
- CompilerType expanded_type = ts->RemangleAsType (dem, transformed, flavor);
2007
- pack_type_or_name.SetCompilerType (expanded_type);
1974
+ if (!transformed)
1975
+ return transformed.takeError ();
1976
+ if (is_indirect)
1977
+ *is_indirect = indirect;
1978
+ return ts->RemangleAsType (dem, *transformed, flavor);
1979
+ }
1980
+
1981
+ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack (
1982
+ ValueObject &in_value, CompilerType pack_type,
1983
+ lldb::DynamicValueType use_dynamic, TypeAndOrName &pack_type_or_name,
1984
+ Address &address, Value::ValueType &value_type) {
1985
+ Log *log (GetLog (LLDBLog::Types));
1986
+ // Return a tuple type, with one element per pack element and its
1987
+ // type has all DependentGenericParamType that appear in type packs
1988
+ // substituted.
1989
+
1990
+ StackFrameSP frame = in_value.GetExecutionContextRef ().GetFrameSP ();
1991
+ if (!frame)
1992
+ return false ;
1993
+
1994
+ // This type has already been resolved?
1995
+ auto ts =
1996
+ pack_type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwiftTypeRef>();
1997
+ if (!ts)
1998
+ return false ;
1999
+ if (auto info = ts->IsSILPackType (pack_type))
2000
+ if (info->expanded )
2001
+ return false ;
2002
+
2003
+ bool indirect = false ;
2004
+ llvm::Expected<CompilerType> expanded_type =
2005
+ BindGenericPackType (*frame, pack_type, &indirect);
2006
+ if (!expanded_type) {
2007
+ LLDB_LOG_ERROR (GetLog (LLDBLog::Types), expanded_type.takeError (), " {0}" );
2008
+ return false ;
2009
+ }
2010
+ pack_type_or_name.SetCompilerType (*expanded_type);
2008
2011
2009
2012
AddressType address_type;
2010
2013
lldb::addr_t addr = in_value.GetAddressOf (true , &address_type);
@@ -2014,7 +2017,7 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Pack(
2014
2017
addr = GetProcess ().ReadPointerFromMemory (addr, status);
2015
2018
if (status.Fail ()) {
2016
2019
LLDB_LOG (log, " failed to dereference indirect pack: {0}" ,
2017
- expanded_type. GetMangledTypeName ());
2020
+ expanded_type-> GetMangledTypeName ());
2018
2021
return false ;
2019
2022
}
2020
2023
}
@@ -3425,7 +3428,6 @@ SwiftLanguageRuntime::GetSwiftRuntimeTypeInfo(
3425
3428
CompilerType type, ExecutionContextScope *exe_scope,
3426
3429
swift::reflection::TypeRef const **out_tr) {
3427
3430
Log *log (GetLog (LLDBLog::Types));
3428
-
3429
3431
if (log && log->GetVerbose ())
3430
3432
LLDB_LOG (log,
3431
3433
" [SwiftLanguageRuntime::GetSwiftRuntimeTypeInfo] Getting "
0 commit comments