@@ -53,6 +53,14 @@ using namespace lldb_private;
53
53
54
54
namespace lldb_private {
55
55
56
+ std::string toString (const swift::reflection::TypeRef *tr) {
57
+ if (!tr)
58
+ return " null typeref" ;
59
+ std::stringstream s;
60
+ tr->dump (s);
61
+ return s.str ();
62
+ }
63
+
56
64
static lldb::addr_t
57
65
MaskMaybeBridgedPointer (Process &process, lldb::addr_t addr,
58
66
lldb::addr_t *masked_bits = nullptr ) {
@@ -686,11 +694,11 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
686
694
687
695
auto ts = type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwiftTypeRef>();
688
696
if (!ts)
689
- return llvm::make_error< llvm::StringError>( " no Swift typesystem " ,
690
- llvm::inconvertibleErrorCode () );
697
+ return llvm::createStringError ( llvm::inconvertibleErrorCode () ,
698
+ " no Swift typesystem " );
691
699
if (!type)
692
- return llvm::make_error< llvm::StringError>( " invalid type " ,
693
- llvm::inconvertibleErrorCode () );
700
+ return llvm::createStringError ( llvm::inconvertibleErrorCode () ,
701
+ " invalid type " );
694
702
695
703
// Deal with the LLDB-only SILPackType variant.
696
704
if (auto pack_type = ts->IsSILPackType (type))
@@ -718,10 +726,10 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
718
726
const swift::reflection::TypeRef *tr = nullptr ;
719
727
auto *ti = GetSwiftRuntimeTypeInfo (type, exe_scope, &tr);
720
728
if (!ti)
721
- return llvm::make_error<llvm::StringError>(
729
+ return llvm::createStringError (
730
+ llvm::inconvertibleErrorCode (),
722
731
" could not get Swift runtime type info for type " +
723
- type.GetMangledTypeName ().GetString (),
724
- llvm::inconvertibleErrorCode ());
732
+ type.GetMangledTypeName ().GetString ());
725
733
if (llvm::isa<swift::reflection::BuiltinTypeInfo>(ti)) {
726
734
// This logic handles Swift Builtin types. By handling them now, the cost of
727
735
// unnecessarily loading ASTContexts can be avoided. Builtin types are
@@ -734,10 +742,10 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
734
742
" {0}: unrecognized builtin type info or this is a Clang type "
735
743
" without DWARF debug info" ,
736
744
type.GetMangledTypeName ());
737
- return llvm::make_error< llvm::StringError>(
738
- " missing debug info for Clang type \" " +
739
- type.GetDisplayTypeName ().GetString () + " \" " ,
740
- llvm::inconvertibleErrorCode () );
745
+ return llvm::createStringError ( llvm::inconvertibleErrorCode (),
746
+ " missing debug info for Clang type \" " +
747
+ type.GetDisplayTypeName ().GetString () +
748
+ " \" " );
741
749
}
742
750
// Structs and Tuples.
743
751
if (auto *rti = llvm::dyn_cast<swift::reflection::RecordTypeInfo>(ti)) {
@@ -782,18 +790,18 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
782
790
}
783
791
784
792
if (!tr)
785
- return llvm::make_error< llvm::StringError>(
786
- " could not typeref for " + type. GetMangledTypeName (). GetString (),
787
- llvm::inconvertibleErrorCode ());
793
+ return llvm::createStringError ( llvm::inconvertibleErrorCode (),
794
+ " could not typeref for " +
795
+ type. GetMangledTypeName (). GetString ());
788
796
789
797
// Existentials.
790
798
if (size_t n = GetExistentialSyntheticChildren (ts, tr, ti).size ())
791
799
return n;
792
800
793
801
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
794
802
if (!reflection_ctx)
795
- return llvm::make_error< llvm::StringError>(
796
- " no reflection context" , llvm::inconvertibleErrorCode () );
803
+ return llvm::createStringError ( llvm::inconvertibleErrorCode (),
804
+ " no reflection context" );
797
805
798
806
LLDBTypeInfoProvider tip (*this , exe_scope);
799
807
auto *cti = reflection_ctx->GetClassInstanceTypeInfo (
@@ -810,18 +818,15 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
810
818
return rti->getNumFields () + 1 ;
811
819
return rti->getNumFields ();
812
820
}
813
- return llvm::make_error<llvm::StringError>(
814
- " No Swift runtime type info for " +
815
- type.GetMangledTypeName ().GetString (),
816
- llvm::inconvertibleErrorCode ());
821
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
822
+ " No Swift runtime type info for " +
823
+ type.GetMangledTypeName ().GetString ());
817
824
}
818
825
819
826
LogUnimplementedTypeKind (__FUNCTION__, type);
820
- return llvm::make_error<llvm::StringError>(
821
- " GetNumChildren unimplemented for type " +
822
- type.GetMangledTypeName ().GetString (),
823
- llvm::inconvertibleErrorCode ());
824
- {};
827
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
828
+ " GetNumChildren unimplemented for type " +
829
+ type.GetMangledTypeName ().GetString ());
825
830
}
826
831
827
832
std::optional<unsigned >
@@ -1097,7 +1102,8 @@ SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
1097
1102
}
1098
1103
}
1099
1104
1100
- CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex (
1105
+ llvm::Expected<CompilerType>
1106
+ SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex (
1101
1107
CompilerType type, size_t idx, bool transparent_pointers,
1102
1108
bool omit_empty_base_classes, bool ignore_array_bounds,
1103
1109
std::string &child_name, uint32_t &child_byte_size,
@@ -1107,7 +1113,8 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1107
1113
uint64_t &language_flags) {
1108
1114
auto ts = type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwiftTypeRef>();
1109
1115
if (!ts)
1110
- return {};
1116
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1117
+ " no type system" );
1111
1118
1112
1119
lldb::addr_t pointer = LLDB_INVALID_ADDRESS;
1113
1120
ExecutionContext exe_ctx;
@@ -1192,16 +1199,16 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1192
1199
auto *ti = GetSwiftRuntimeTypeInfo (
1193
1200
type, exe_ctx.GetBestExecutionContextScope (), &tr);
1194
1201
if (!ti)
1195
- return {};
1202
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1203
+ " could not get runtime type info for" +
1204
+ toString (tr));
1205
+
1196
1206
// Structs and Tuples.
1197
1207
if (auto *rti =
1198
1208
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
1199
1209
auto fields = rti->getFields ();
1200
1210
1201
1211
// Handle tuples.
1202
- if (idx >= rti->getNumFields ())
1203
- LLDB_LOGF (GetLog (LLDBLog::Types), " index %zu is out of bounds (%d)" , idx,
1204
- rti->getNumFields ());
1205
1212
std::optional<TypeSystemSwift::TupleElement> tuple;
1206
1213
if (rti->getRecordKind () == swift::reflection::RecordKind::Tuple)
1207
1214
tuple = ts->GetTupleElement (type.GetOpaqueQualType (), idx);
@@ -1220,6 +1227,11 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1220
1227
language_flags = 0 ;
1221
1228
return ts->GetRawPointerType ();
1222
1229
}
1230
+ if (idx - 3 >= fields.size ())
1231
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1232
+ llvm::Twine (" index" ) + llvm::Twine (idx) +
1233
+ " is out of bounds (" +
1234
+ llvm::Twine (fields.size ()) + " )" );
1223
1235
return get_from_field_info (fields[idx - 3 ], tuple, false );
1224
1236
}
1225
1237
if (rti->getRecordKind () ==
@@ -1239,6 +1251,11 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1239
1251
return protocol_child.get_type ();
1240
1252
}
1241
1253
}
1254
+ if (idx >= fields.size ())
1255
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1256
+ llvm::Twine (" index" ) + llvm::Twine (idx) +
1257
+ " is out of bounds (" +
1258
+ llvm::Twine (fields.size ()) + " )" );
1242
1259
return get_from_field_info (fields[idx], tuple, true );
1243
1260
}
1244
1261
// Enums.
@@ -1251,9 +1268,10 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1251
1268
if (i++ == idx)
1252
1269
return get_from_field_info (enum_case, {}, true );
1253
1270
}
1254
- LLDB_LOG (GetLog (LLDBLog::Types), " index {0} is out of bounds ({1})" , idx,
1255
- eti->getNumPayloadCases ());
1256
- return {};
1271
+ return llvm::createStringError (
1272
+ llvm::inconvertibleErrorCode (),
1273
+ llvm::Twine (" index" ) + llvm::Twine (idx) + " is out of bounds (" +
1274
+ llvm::Twine (eti->getNumPayloadCases ()) + " )" );
1257
1275
}
1258
1276
if (auto *rti =
1259
1277
llvm::dyn_cast_or_null<swift::reflection::ReferenceTypeInfo>(ti)) {
@@ -1272,9 +1290,10 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1272
1290
return protocol_child.get_type ();
1273
1291
}
1274
1292
if (i) {
1275
- LLDB_LOG (GetLog (LLDBLog::Types), " index {0} is out of bounds ({1})" , idx,
1276
- i - 1 );
1277
- return {};
1293
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1294
+ llvm::Twine (" index" ) + llvm::Twine (idx) +
1295
+ " is out of bounds (" +
1296
+ llvm::Twine (i - 1 ) + " )" );
1278
1297
}
1279
1298
1280
1299
// Objects.
@@ -1303,7 +1322,9 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1303
1322
1304
1323
// Try the instance type metadata.
1305
1324
if (!valobj)
1306
- return {};
1325
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1326
+ " object has no address" );
1327
+
1307
1328
bool found_start = false ;
1308
1329
using namespace swift ::Demangle;
1309
1330
Demangler dem;
@@ -1314,12 +1335,16 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1314
1335
1315
1336
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
1316
1337
if (!reflection_ctx)
1317
- return {};
1338
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1339
+ " no reflection context" );
1340
+
1318
1341
CompilerType instance_type = valobj->GetCompilerType ();
1319
1342
auto instance_ts =
1320
1343
instance_type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwift>();
1321
1344
if (!instance_ts)
1322
- return {};
1345
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1346
+ " no typesystem" );
1347
+
1323
1348
// LLDBTypeInfoProvider needs to be kept alive while supers gets accessed.
1324
1349
llvm::SmallVector<SuperClassType, 2 > supers;
1325
1350
auto superclass_finder = [&](SuperClassType sc) -> bool {
@@ -1371,7 +1396,9 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1371
1396
return get_from_field_info (fields[idx], tuple, true );
1372
1397
}
1373
1398
}
1374
- return {};
1399
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1400
+ llvm::Twine (" index" ) + llvm::Twine (idx) +
1401
+ " is out of bounds" );
1375
1402
}
1376
1403
1377
1404
// Handle the artificial base class fields.
@@ -1387,7 +1414,7 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1387
1414
// field in the base class.
1388
1415
if (!type_ref) {
1389
1416
child_name = " <base class>" ;
1390
- return {} ;
1417
+ return CompilerType () ;
1391
1418
}
1392
1419
CompilerType super_type = GetTypeFromTypeRef (*ts, type_ref);
1393
1420
child_name = super_type.GetTypeName ().GetStringRef ().str ();
@@ -1411,24 +1438,27 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
1411
1438
// Handle the "real" fields.
1412
1439
auto *object = supers[0 ].get_record_type_info ();
1413
1440
if (!object)
1414
- return {};
1441
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1442
+ " no record type info" );
1415
1443
for (auto &field : object->getFields ())
1416
1444
if (i++ == idx)
1417
1445
return get_from_field_info (field, {}, true );
1418
1446
1419
- LLDB_LOG (GetLog (LLDBLog::Types), " index {0} is out of bounds ({1})" , idx,
1420
- i - 1 );
1421
- return {};
1447
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1448
+ llvm::Twine (" index" ) + llvm::Twine (idx) +
1449
+ " is out of bounds (" +
1450
+ llvm::Twine (i - 1 ) + " )" );
1422
1451
}
1423
1452
if (llvm::dyn_cast_or_null<swift::reflection::BuiltinTypeInfo>(ti)) {
1424
1453
// Clang enums have an artificial rawValue property. We could
1425
1454
// consider handling them here, but
1426
1455
// TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex can also
1427
1456
// handle them and without a Process.
1428
- return {} ;
1457
+ return CompilerType () ;
1429
1458
}
1430
1459
LogUnimplementedTypeKind (__FUNCTION__, type);
1431
- return {};
1460
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
1461
+ " not implemented" );
1432
1462
}
1433
1463
1434
1464
bool SwiftLanguageRuntimeImpl::ForEachSuperClassType (
0 commit comments