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