From 9e0a39f3787ac055631891be9062dcd561cf4501 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 1 Nov 2021 15:55:16 +0100 Subject: [PATCH] [lldb] Add a test for class loading via member typedefs This is currently only tested indirectly in the huge stdlibc++ formatter tests. --- .../cpp/class-loading-via-member-typedef/Makefile | 3 ++ .../TestClassLoadingViaMemberTypedef.py | 41 ++++++++++++++++++++++ .../cpp/class-loading-via-member-typedef/main.cpp | 31 ++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 lldb/test/API/lang/cpp/class-loading-via-member-typedef/Makefile create mode 100644 lldb/test/API/lang/cpp/class-loading-via-member-typedef/TestClassLoadingViaMemberTypedef.py create mode 100644 lldb/test/API/lang/cpp/class-loading-via-member-typedef/main.cpp diff --git a/lldb/test/API/lang/cpp/class-loading-via-member-typedef/Makefile b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/Makefile new file mode 100644 index 0000000..99998b2 --- /dev/null +++ b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/lang/cpp/class-loading-via-member-typedef/TestClassLoadingViaMemberTypedef.py b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/TestClassLoadingViaMemberTypedef.py new file mode 100644 index 0000000..6d1a85f --- /dev/null +++ b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/TestClassLoadingViaMemberTypedef.py @@ -0,0 +1,41 @@ +""" +Tests loading of classes when the loading is triggered via a typedef inside the +class (and not via the normal LLDB lookup that first resolves the surrounding +class). +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test(self): + self.build() + self.createTestTarget() + + # Print the top-level typedef which triggers the loading of the class + # that the typedef is defined inside. + self.expect_expr( + "pull_in_classes", + result_type="StructWithMember::MemberTypedef", + result_value="0", + ) + + # Print the classes and check their types. + self.expect_expr( + "struct_to_print", + result_type="StructWithMember", + result_children=[ + ValueCheck( + name="m", + type="StructWithNested::Nested::OtherTypedef", + children=[ValueCheck(name="i", value="0", type="int")], + ) + ], + ) diff --git a/lldb/test/API/lang/cpp/class-loading-via-member-typedef/main.cpp b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/main.cpp new file mode 100644 index 0000000..ba08d3b --- /dev/null +++ b/lldb/test/API/lang/cpp/class-loading-via-member-typedef/main.cpp @@ -0,0 +1,31 @@ +struct TopLevelStruct { + int i; +}; + +// Contains a templated nested class with a typedef. +struct StructWithNested { + template + struct Nested { + // Typedef in a class. Intended to be referenced directly so that it can + // trigger the loading of the surrounding classes. + typedef TopLevelStruct OtherTypedef; + }; +}; + +// Contains a typedef. +struct StructWithMember { + // This member pulls in the typedef (and classes) above. + StructWithNested::Nested::OtherTypedef m; + // Typedef in a class. Intended to be referenced directly so that it can + // trigger the loading of the surrounding class. + typedef int MemberTypedef; +}; + +// This is printed and will pull in the typedef in StructWithmember. +StructWithMember::MemberTypedef pull_in_classes; + + +StructWithMember struct_to_print; + + +int main() {} -- 2.7.4