Skip to content

[lldb] Split TestSwiftEmbeddedFrameVariable into two tests #8464

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 3 commits into from
Mar 25, 2024
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
1 change: 1 addition & 0 deletions lldb/include/lldb/Core/ModuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ModuleListProperties : public Properties {

AutoBool GetSwiftEnableCxxInterop() const;
AutoBool GetSwiftEnableFullDwarfDebugging() const;
bool GetSwiftEnableASTContext() const;
// END SWIFT

FileSpec GetClangModulesCachePath() const;
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Core/CoreProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ let Definition = "modulelist" in {
DefaultEnumValue<"llvm::to_underlying(AutoBool::Auto)">,
EnumValues<"OptionEnumValues(g_enable_full_dwarf_debugging)">,
Desc<"Read full debug information from DWARF for Swift debugging. By default LLDB will use DWARF debug information if it cannot use reflection metadata.">;
def SwiftEnableASTContext: Property<"swift-enable-ast-context", "Boolean">,
Global,
DefaultTrue,
Desc<"Enable instantiating Swift AST contexts.">;
// END SWIFT
def SymLinkPaths: Property<"debug-info-symlink-paths", "FileSpecList">,
Global,
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ AutoBool ModuleListProperties::GetSwiftEnableFullDwarfDebugging() const {
idx, static_cast<AutoBool>(
g_modulelist_properties[idx].default_uint_value));
}

bool ModuleListProperties::GetSwiftEnableASTContext() const {
const uint32_t idx = ePropertySwiftEnableASTContext;
return GetPropertyAtIndexAs<bool>(
idx, g_modulelist_properties[idx].default_uint_value != 0);
}
// END SWIFT

FileSpec ModuleListProperties::GetLLDBIndexCachePath() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ DWARFASTParserSwift::getBuiltinTypeDescriptor(
if (byte_size == LLDB_INVALID_ADDRESS)
return {};

auto alignment = die.GetAttributeValueAsUnsigned(DW_AT_alignment, 8);
auto alignment = die.GetAttributeValueAsUnsigned(DW_AT_alignment,
byte_size ? byte_size : 8);

// TODO: this seems simple to calculate but maybe we should encode the stride
// in DWARF? That's what reflection metadata does.
Expand Down
16 changes: 16 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,10 @@ SwiftASTContext::SwiftASTContext(std::string description,
: TypeSystemSwift(), m_typeref_typesystem(&typeref_typesystem),
m_compiler_invocation_ap(new swift::CompilerInvocation()),
m_diagnostic_consumer_ap(new StoringDiagnosticConsumer(*this)) {
assert(
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableASTContext() &&
"Swift AST context instantiation is disabled!");

m_description = description;

// Set the clang modules cache path.
Expand Down Expand Up @@ -1884,6 +1888,10 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
if (!SwiftASTContextSupportsLanguage(language))
return lldb::TypeSystemSP();

if (!ModuleList::GetGlobalModuleListProperties()
.GetSwiftEnableASTContext())
return lldb::TypeSystemSP();

std::string m_description;
{
llvm::raw_string_ostream ss(m_description);
Expand Down Expand Up @@ -2359,6 +2367,10 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
if (!SwiftASTContextSupportsLanguage(language))
return lldb::TypeSystemSP();

if (!ModuleList::GetGlobalModuleListProperties()
.GetSwiftEnableASTContext())
return lldb::TypeSystemSP();

LLDB_SCOPED_TIMER();
std::string m_description = "SwiftASTContextForExpressions";
std::vector<swift::PluginSearchOption> plugin_search_options;
Expand Down Expand Up @@ -2650,6 +2662,10 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
TypeSystemSwiftTypeRefForExpressions &typeref_typesystem) {
LLDB_SCOPED_TIMER();

if (!ModuleList::GetGlobalModuleListProperties()
.GetSwiftEnableASTContext())
return lldb::TypeSystemSP();

CompileUnit *cu = sc.comp_unit;
StringRef swift_module_name = TypeSystemSwiftTypeRef::GetSwiftModuleFor(&sc);
std::string m_description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ class TestSwiftEmbeddedFrameVariable(TestBase):
@swiftTest
def test(self):
self.build()
self.implementation()

@skipUnlessDarwin
@swiftTest
def test_without_ast(self):
"""Run the test turning off instantion of Swift AST contexts in order to ensure that all type information comes from DWARF"""
self.build()
self.runCmd("setting set symbols.swift-enable-ast-context false")
self.implementation()

def implementation(self):
self.runCmd("setting set symbols.swift-enable-full-dwarf-debugging true")

target, process, thread, _ = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
Expand All @@ -19,153 +31,151 @@ def test(self):

varB = frame.FindVariable("varB")
field = varB.GetChildMemberWithName("a").GetChildMemberWithName("field")
lldbutil.check_variable(self, field, False, value='4.5')
lldbutil.check_variable(self, field, False, value="4.5")
b = varB.GetChildMemberWithName("b")
lldbutil.check_variable(self, b, False, value='123456')
lldbutil.check_variable(self, b, False, value="123456")

tuple = frame.FindVariable("tuple")
first = tuple.GetChildAtIndex(0)
field = first.GetChildMemberWithName("field")
lldbutil.check_variable(self, field, False, value='4.5')
lldbutil.check_variable(self, field, False, value="4.5")
second = tuple.GetChildAtIndex(1)
a = second.GetChildMemberWithName("a")
field = a.GetChildMemberWithName("field")
lldbutil.check_variable(self, field, False, value='4.5')
lldbutil.check_variable(self, field, False, value="4.5")
b = second.GetChildMemberWithName("b")
lldbutil.check_variable(self, b, False, value='123456')
lldbutil.check_variable(self, b, False, value="123456")

nonPayload1 = frame.FindVariable("nonPayload1")
lldbutil.check_variable(self, nonPayload1, False, value='one')
lldbutil.check_variable(self, nonPayload1, False, value="one")

nonPayload2 = frame.FindVariable("nonPayload2")
lldbutil.check_variable(self, nonPayload2, False, value='two')
lldbutil.check_variable(self, nonPayload2, False, value="two")

singlePayload = frame.FindVariable("singlePayload")
payload = singlePayload.GetChildMemberWithName('payload')
field = payload.GetChildMemberWithName('a').GetChildMemberWithName('field')
lldbutil.check_variable(self, field, False, value='4.5')
b = payload.GetChildMemberWithName('b')
lldbutil.check_variable(self, b, False, value='123456')
payload = singlePayload.GetChildMemberWithName("payload")
field = payload.GetChildMemberWithName("a").GetChildMemberWithName("field")
lldbutil.check_variable(self, field, False, value="4.5")
b = payload.GetChildMemberWithName("b")
lldbutil.check_variable(self, b, False, value="123456")

emptySinglePayload = frame.FindVariable("emptySinglePayload")
lldbutil.check_variable(self, emptySinglePayload, False, value='nonPayloadTwo')
lldbutil.check_variable(self, emptySinglePayload, False, value="nonPayloadTwo")

smallMultipayloadEnum1 = frame.FindVariable("smallMultipayloadEnum1")
one = smallMultipayloadEnum1.GetChildMemberWithName("one")
lldbutil.check_variable(self, one, False, value='two')
lldbutil.check_variable(self, one, False, value="two")

smallMultipayloadEnum2 = frame.FindVariable("smallMultipayloadEnum2")
two = smallMultipayloadEnum2.GetChildMemberWithName("two")
lldbutil.check_variable(self, two, False, value='one')

lldbutil.check_variable(self, two, False, value="one")

bigMultipayloadEnum1 = frame.FindVariable("bigMultipayloadEnum1")
one = bigMultipayloadEnum1.GetChildMemberWithName("one")
first = one.GetChildAtIndex(0).GetChildMemberWithName("supField")
second = one.GetChildAtIndex(1).GetChildMemberWithName("supField")
third = one.GetChildAtIndex(2).GetChildMemberWithName("supField")
lldbutil.check_variable(self, first, False, value='42')
lldbutil.check_variable(self, second, False, value='43')
lldbutil.check_variable(self, third, False, value='44')

lldbutil.check_variable(self, first, False, value="42")
lldbutil.check_variable(self, second, False, value="43")
lldbutil.check_variable(self, third, False, value="44")

fullMultipayloadEnum1 = frame.FindVariable("fullMultipayloadEnum1")
one = fullMultipayloadEnum1.GetChildMemberWithName("one")
lldbutil.check_variable(self, one, False, value='120')
lldbutil.check_variable(self, one, False, value="120")

fullMultipayloadEnum2 = frame.FindVariable("fullMultipayloadEnum2")
two = fullMultipayloadEnum2.GetChildMemberWithName("two")
lldbutil.check_variable(self, two, False, value='9.5')
lldbutil.check_variable(self, two, False, value="9.5")

bigFullMultipayloadEnum1 = frame.FindVariable("bigFullMultipayloadEnum1")
one = bigFullMultipayloadEnum1.GetChildMemberWithName("one")
first = one.GetChildAtIndex(0)
second = one.GetChildAtIndex(1)
lldbutil.check_variable(self, first, False, value='209')
lldbutil.check_variable(self, second, False, value='315')
lldbutil.check_variable(self, first, False, value="209")
lldbutil.check_variable(self, second, False, value="315")

bigFullMultipayloadEnum2 = frame.FindVariable("bigFullMultipayloadEnum2")
two = bigFullMultipayloadEnum2.GetChildMemberWithName("two")
first = two.GetChildAtIndex(0)
second = two.GetChildAtIndex(1)
lldbutil.check_variable(self, first, False, value='452.5')
lldbutil.check_variable(self, second, False, value='753.5')

lldbutil.check_variable(self, first, False, value="452.5")
lldbutil.check_variable(self, second, False, value="753.5")

sup = frame.FindVariable("sup")
supField = sup.GetChildMemberWithName("supField")
lldbutil.check_variable(self, supField, False, value='42')
lldbutil.check_variable(self, supField, False, value="42")

sub = frame.FindVariable("sub")
supField = sub.GetChildMemberWithName("supField")
lldbutil.check_variable(self, supField, False, value='42')
lldbutil.check_variable(self, supField, False, value="42")
subField = sub.GetChildMemberWithName("subField")
a = subField.GetChildMemberWithName("a")
field = a.GetChildMemberWithName("field")
lldbutil.check_variable(self, field, False, value='4.5')
lldbutil.check_variable(self, field, False, value="4.5")
b = subField.GetChildMemberWithName("b")
lldbutil.check_variable(self, b, False, value='123456')
lldbutil.check_variable(self, b, False, value="123456")

subSub = frame.FindVariable("subSub")
supField = subSub.GetChildMemberWithName("supField")
lldbutil.check_variable(self, supField, False, value='42')
lldbutil.check_variable(self, supField, False, value="42")
subField = subSub.GetChildMemberWithName("subField")
a = subField.GetChildMemberWithName("a")
field = a.GetChildMemberWithName("field")
lldbutil.check_variable(self, field, False, value='4.5')
lldbutil.check_variable(self, field, False, value="4.5")
b = subField.GetChildMemberWithName("b")
lldbutil.check_variable(self, b, False, value='123456')
lldbutil.check_variable(self, b, False, value="123456")

subSubField = subSub.GetChildMemberWithName("subSubField").GetChildMemberWithName("field")
lldbutil.check_variable(self, subSubField, False, value='4.5')
subSubField = subSub.GetChildMemberWithName(
"subSubField"
).GetChildMemberWithName("field")
lldbutil.check_variable(self, subSubField, False, value="4.5")

gsp = frame.FindVariable("gsp")
t = gsp.GetChildMemberWithName("t")
lldbutil.check_variable(self, t, False, value='42')
lldbutil.check_variable(self, t, False, value="42")
u = gsp.GetChildMemberWithName("u")
lldbutil.check_variable(self, u, False, value='94.5')
lldbutil.check_variable(self, u, False, value="94.5")

gsp2 = frame.FindVariable("gsp2")
t = gsp2.GetChildMemberWithName("t")
supField = t.GetChildMemberWithName("supField")
lldbutil.check_variable(self, supField, False, value='42')
lldbutil.check_variable(self, supField, False, value="42")
u = gsp2.GetChildMemberWithName("u")
a = u.GetChildMemberWithName("a")
field = a.GetChildMemberWithName("field")
lldbutil.check_variable(self, field, False, value='4.5')
lldbutil.check_variable(self, field, False, value="4.5")
b = u.GetChildMemberWithName("b")
lldbutil.check_variable(self, b, False, value='123456')
lldbutil.check_variable(self, b, False, value="123456")

gsp3 = frame.FindVariable("gsp3")
t = gsp3.GetChildMemberWithName("t")
one = t.GetChildMemberWithName("one")
first = one.GetChildAtIndex(0)
second = one.GetChildAtIndex(1)
lldbutil.check_variable(self, first, False, value='209')
lldbutil.check_variable(self, second, False, value='315')
lldbutil.check_variable(self, first, False, value="209")
lldbutil.check_variable(self, second, False, value="315")
u = gsp3.GetChildMemberWithName("u")
two = u.GetChildMemberWithName("two")
lldbutil.check_variable(self, two, False, value='one')
lldbutil.check_variable(self, two, False, value="one")

gcp = frame.FindVariable("gcp")
t = gcp.GetChildMemberWithName("t")
lldbutil.check_variable(self, t, False, value='55.5')
lldbutil.check_variable(self, t, False, value="55.5")
u = gcp.GetChildMemberWithName("u")
lldbutil.check_variable(self, u, False, value='9348')

lldbutil.check_variable(self, u, False, value="9348")

either = frame.FindVariable("either")
left = either.GetChildMemberWithName("left")
lldbutil.check_variable(self, left, False, value='1234')
lldbutil.check_variable(self, left, False, value="1234")

either2 = frame.FindVariable("either2")
right = either2.GetChildMemberWithName("right")
t = right.GetChildMemberWithName("t")
one = t.GetChildMemberWithName("one")
first = one.GetChildAtIndex(0)
second = one.GetChildAtIndex(1)
lldbutil.check_variable(self, first, False, value='209')
lldbutil.check_variable(self, second, False, value='315')
lldbutil.check_variable(self, first, False, value="209")
lldbutil.check_variable(self, second, False, value="315")
u = right.GetChildMemberWithName("u")
two = u.GetChildMemberWithName("two")
lldbutil.check_variable(self, two, False, value='one')
lldbutil.check_variable(self, two, False, value="one")