Skip to content

Commit 56a74c4

Browse files
committed
RemoteAST: Add new entry point to unwrap an Error existential container
The getDynamicTypeAndAddressForExistential() function takes the address of an existential value; so when looking at an Error, this is the address of the reference, not the address of the instance. lldb needs to look at Error instances too, so add a new entry point named getDynamicTypeAndAddressForError() which avoids the extra dereference. This will be tested on the lldb side.
1 parent bd3b451 commit 56a74c4

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

include/swift/RemoteAST/RemoteAST.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class Result {
136136
}
137137
};
138138

139+
using OpenedExistential = Result<std::pair<Type, remote::RemoteAddress>>;
140+
139141
/// A context for performing an operation relating the remote process with
140142
/// the AST. This may be discarded and recreated at any time without danger,
141143
/// but reusing a context across multiple calls may allow some redundant work
@@ -212,11 +214,17 @@ class RemoteASTContext {
212214
Result<remote::RemoteAddress>
213215
getHeapMetadataForObject(remote::RemoteAddress address);
214216

217+
/// Resolve the dynamic type and the value address of an error existential
218+
/// object, Unlike getDynamicTypeAndAddressForExistential(), this function
219+
/// takes the address of the instance and not the address of the reference.
220+
OpenedExistential
221+
getDynamicTypeAndAddressForError(remote::RemoteAddress object);
222+
215223
/// Given an existential and its static type, resolve its dynamic
216224
/// type and address. A single step of unwrapping is performed, i.e. if the
217225
/// value stored inside the existential is itself an existential, the
218226
/// caller can decide whether to iterate itself.
219-
Result<std::pair<Type, remote::RemoteAddress>>
227+
OpenedExistential
220228
getDynamicTypeAndAddressForExistential(remote::RemoteAddress address,
221229
Type staticType);
222230
};

lib/RemoteAST/RemoteAST.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ class RemoteASTContextImpl {
104104
getDeclForRemoteNominalTypeDescriptor(RemoteAddress descriptor) = 0;
105105
virtual Result<RemoteAddress>
106106
getHeapMetadataForObject(RemoteAddress object) = 0;
107-
virtual Result<std::pair<Type, RemoteAddress>>
107+
virtual OpenedExistential
108+
getDynamicTypeAndAddressForError(RemoteAddress object) = 0;
109+
virtual OpenedExistential
108110
getDynamicTypeAndAddressForExistential(RemoteAddress object,
109111
Type staticType) = 0;
110112

@@ -476,7 +478,7 @@ class RemoteASTContextConcreteImpl final : public RemoteASTContextImpl {
476478
return getFailure<RemoteAddress>();
477479
}
478480

479-
Result<std::pair<Type, RemoteAddress>>
481+
OpenedExistential
480482
getDynamicTypeAndAddressClassExistential(RemoteAddress object) {
481483
auto pointerval = Reader.readPointerValue(object.getAddressData());
482484
if (!pointerval)
@@ -491,13 +493,18 @@ class RemoteASTContextConcreteImpl final : public RemoteASTContextImpl {
491493
RemoteAddress(*pointerval));
492494
}
493495

494-
Result<std::pair<Type, RemoteAddress>>
495-
getDynamicTypeAndAddressErrorExistential(RemoteAddress object) {
496-
auto pointerval = Reader.readPointerValue(object.getAddressData());
497-
if (!pointerval)
498-
return getFailure<std::pair<Type, RemoteAddress>>();
496+
OpenedExistential
497+
getDynamicTypeAndAddressErrorExistential(RemoteAddress object,
498+
bool dereference=true) {
499+
if (dereference) {
500+
auto pointerval = Reader.readPointerValue(object.getAddressData());
501+
if (!pointerval)
502+
return getFailure<std::pair<Type, RemoteAddress>>();
503+
object = RemoteAddress(*pointerval);
504+
}
505+
499506
auto result =
500-
Reader.readMetadataAndValueErrorExistential(RemoteAddress(*pointerval));
507+
Reader.readMetadataAndValueErrorExistential(object);
501508
if (!result)
502509
return getFailure<std::pair<Type, RemoteAddress>>();
503510

@@ -525,7 +532,7 @@ class RemoteASTContextConcreteImpl final : public RemoteASTContextImpl {
525532
std::move(valueAddress));
526533
}
527534

528-
Result<std::pair<Type, RemoteAddress>>
535+
OpenedExistential
529536
getDynamicTypeAndAddressOpaqueExistential(RemoteAddress object) {
530537
auto result = Reader.readMetadataAndValueOpaqueExistential(object);
531538
if (!result)
@@ -553,7 +560,7 @@ class RemoteASTContextConcreteImpl final : public RemoteASTContextImpl {
553560
std::move(valueAddress));
554561
}
555562

556-
Result<std::pair<Type, RemoteAddress>>
563+
OpenedExistential
557564
getDynamicTypeAndAddressExistentialMetatype(RemoteAddress object) {
558565
// The value of the address is just the input address.
559566
// The type is obtained through the following sequence of steps:
@@ -573,11 +580,20 @@ class RemoteASTContextConcreteImpl final : public RemoteASTContextImpl {
573580
std::move(object));
574581
}
575582

583+
/// Resolve the dynamic type and the value address of an error existential
584+
/// object, Unlike getDynamicTypeAndAddressForExistential(), this function
585+
/// takes the address of the instance and not the address of the reference.
586+
OpenedExistential
587+
getDynamicTypeAndAddressForError(RemoteAddress object) override {
588+
return getDynamicTypeAndAddressErrorExistential(object,
589+
/*dereference=*/false);
590+
}
591+
576592
/// Resolve the dynamic type and the value address of an existential,
577593
/// given its address and its static type. For class and error existentials,
578594
/// this API takes a pointer to the instance reference rather than the
579595
/// instance reference itself.
580-
Result<std::pair<Type, RemoteAddress>>
596+
OpenedExistential
581597
getDynamicTypeAndAddressForExistential(RemoteAddress object,
582598
Type staticType) override {
583599
// If this is not an existential, give up.
@@ -658,7 +674,13 @@ RemoteASTContext::getHeapMetadataForObject(remote::RemoteAddress address) {
658674
return asImpl(Impl)->getHeapMetadataForObject(address);
659675
}
660676

661-
Result<std::pair<Type, remote::RemoteAddress>>
677+
OpenedExistential
678+
RemoteASTContext::getDynamicTypeAndAddressForError(
679+
remote::RemoteAddress address) {
680+
return asImpl(Impl)->getDynamicTypeAndAddressForError(address);
681+
}
682+
683+
OpenedExistential
662684
RemoteASTContext::getDynamicTypeAndAddressForExistential(
663685
remote::RemoteAddress address, Type staticType) {
664686
return asImpl(Impl)->getDynamicTypeAndAddressForExistential(address,

0 commit comments

Comments
 (0)