Skip to content

[lldb][swift] Use dynamic types as a fallback in AddVariableInfo #2031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,22 @@ static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
}
}

/// Returns the Swift type for a ValueObject representing a variable.
/// An invalid CompilerType is returned on error.
static CompilerType GetSwiftTypeForVariableValueObject(
lldb::ValueObjectSP valobj_sp, lldb::StackFrameSP &stack_frame_sp,
SwiftLanguageRuntime *runtime, bool use_dynamic_value) {
// Check that the passed ValueObject is valid.
if (!valobj_sp || valobj_sp->GetError().Fail())
return CompilerType();
CompilerType result = valobj_sp->GetCompilerType();
if (use_dynamic_value)
result = runtime->BindGenericTypeParameters(*stack_frame_sp, result);
if (!result.GetTypeSystem()->SupportsLanguage(lldb::eLanguageTypeSwift))
return CompilerType();
return result;
}

/// Create a \c VariableInfo record for \c variable if there isn't
/// already shadowing inner declaration in \c processed_variables.
static llvm::Optional<llvm::Error> AddVariableInfo(
Expand All @@ -602,31 +618,30 @@ static llvm::Optional<llvm::Error> AddVariableInfo(
if (processed_variables.count(overridden_name))
return {};

CompilerType var_type;
if (stack_frame_sp) {
lldb::ValueObjectSP valobj_sp =
stack_frame_sp->GetValueObjectForFrameVariable(variable_sp,
use_dynamic);
if (!stack_frame_sp)
return llvm::None;

if (!valobj_sp || valobj_sp->GetError().Fail()) {
// Ignore the variable if we couldn't find its corresponding
// value object. TODO if the expression tries to use an
// ignored variable, produce a sensible error.
return {};
}
var_type = valobj_sp->GetCompilerType();
if (use_dynamic > lldb::eNoDynamicValues) {
if (auto *stack_frame = stack_frame_sp.get())
var_type =
runtime->BindGenericTypeParameters(*stack_frame, var_type);
}
}
lldb::ValueObjectSP valobj_sp =
stack_frame_sp->GetValueObjectForFrameVariable(variable_sp,
lldb::eNoDynamicValues);

const bool use_dynamic_value = use_dynamic > lldb::eNoDynamicValues;

CompilerType var_type = GetSwiftTypeForVariableValueObject(
valobj_sp, stack_frame_sp, runtime, use_dynamic_value);

if (!var_type.IsValid())
return {};

if (!var_type.GetTypeSystem()->SupportsLanguage(lldb::eLanguageTypeSwift))
return {};
// If the type can't be realized and dynamic types are allowed, fall back to
// the dynamic type.
if (!SwiftASTContext::IsFullyRealized(var_type) && use_dynamic_value) {
var_type = GetSwiftTypeForVariableValueObject(
valobj_sp->GetDynamicValue(use_dynamic), stack_frame_sp, runtime,
use_dynamic_value);
if (!var_type.IsValid())
return {};
}

Status error;
CompilerType target_type = ast_context.ImportType(var_type, error);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import lldbsuite.test.lldbinline as lldbinline
from lldbsuite.test.decorators import *

lldbinline.MakeInlineTest(__file__, globals(), decorators=[swiftTest,
expectedFailureAll #FIXME: This regressed silently due to 2c911bceb06ed376801251bdfd992905a66f276c
])
lldbinline.MakeInlineTest(__file__, globals(), decorators=[swiftTest])
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import lldbsuite.test.lldbinline as lldbinline
from lldbsuite.test.decorators import *

lldbinline.MakeInlineTest(__file__, globals(), decorators=[swiftTest,
expectedFailureAll #FIXME: This regressed silently due to 2c911bceb06ed376801251bdfd992905a66f276c
])
lldbinline.MakeInlineTest(__file__, globals(), decorators=[swiftTest])
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def check_class(self, var_self, broken):
self.expect("fr v self", substrs=["hello", "world"])


@skipIf #FIXME: This regressed silently due to 2c911bceb06ed376801251bdfd992905a66f276c
@skipIf(bugnumber="SR-10216", archs=['ppc64le'])
@swiftTest
def test_unknown_self_objc_ref(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@
import lldbsuite.test.lldbinline as lldbinline
from lldbsuite.test.decorators import *

lldbinline.MakeInlineTest(__file__, globals(), decorators=[
#FIXME: This regressed silently due to 2c911bceb06ed376801251bdfd992905a66f276c
expectedFailureAll,
swiftTest])
lldbinline.MakeInlineTest(__file__, globals(), decorators=[swiftTest])