[Lldb-commits] [lldb] 8b656b8 - [lldb] Re-eanble and rewrite TestCPPStaticMembers

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Tue May 25 02:52:48 PDT 2021


Author: Raphael Isemann
Date: 2021-05-25T11:52:28+02:00
New Revision: 8b656b88462f51396c8c4772e0012549f76f204f

URL: https://github.com/llvm/llvm-project/commit/8b656b88462f51396c8c4772e0012549f76f204f
DIFF: https://github.com/llvm/llvm-project/commit/8b656b88462f51396c8c4772e0012549f76f204f.diff

LOG: [lldb] Re-eanble and rewrite TestCPPStaticMembers

It's not clear why the whole test got disabled, but the linked bug report
has since been fixed and the only part of it that still fails is the test
for the too permissive lookup. This re-enables the test, rewrites it to use
the modern test functions we have and splits the failing part into its
own test that we can skip without disabling the rest.

Added: 
    

Modified: 
    lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
    lldb/test/API/lang/cpp/static_members/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py b/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
index 301f3bc10269a..8acf498bb7f74 100644
--- a/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ b/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -11,51 +11,30 @@
 from lldbsuite.test import lldbutil
 
 
-class CPPStaticMembersTestCase(TestBase):
+class TestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
 
-    @expectedFailure  # llvm.org/pr15401
     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")
-    def test_with_run_command(self):
-        """Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods"""
+    def test_access_from_main(self):
         self.build()
-        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
+        lldbutil.run_to_source_breakpoint(self, "// stop in main", lldb.SBFileSpec("main.cpp"))
 
-        self.set_breakpoint(line_number('main.cpp', '// breakpoint 1'))
-        self.set_breakpoint(line_number('main.cpp', '// breakpoint 2'))
+        self.expect_expr("my_a.m_a", result_type="short", result_value="1")
+        self.expect_expr("my_a.s_b", result_type="long", result_value="2")
+        self.expect_expr("my_a.s_c", result_type="int", result_value="3")
 
-        self.runCmd("process launch", RUN_SUCCEEDED)
-        self.expect("expression my_a.access()",
-                    startstr="(long) $0 = 10")
-
-        self.expect("expression my_a.m_a",
-                    startstr="(short) $1 = 1")
-
-        # Note: SymbolFileDWARF::ParseChildMembers doesn't call
-        # AddFieldToRecordType, consistent with clang's AST layout.
-        self.expect("expression my_a.s_d",
-                    startstr="(int) $2 = 4")
-
-        self.expect("expression my_a.s_b",
-                    startstr="(long) $3 = 2")
-
-        self.expect("expression A::s_b",
-                    startstr="(long) $4 = 2")
-
-        # should not be available in global scope
-        self.expect("expression s_d",
+    def test_access_from_member_function(self):
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "// stop in member function", lldb.SBFileSpec("main.cpp"))
+        self.expect_expr("m_a", result_type="short", result_value="1")
+        self.expect_expr("s_b", result_type="long", result_value="2")
+        self.expect_expr("s_c", result_type="int", result_value="3")
+
+    # Currently lookups find variables that are in any scope.
+    @expectedFailureAll()
+    def test_access_without_scope(self):
+        self.build()
+        self.createTestTarget()
+        self.expect("expression s_c", error=True,
                     startstr="error: use of undeclared identifier 's_d'")
-
-        self.runCmd("process continue")
-        self.expect("expression m_c",
-                    startstr="(char) $5 = \'\\x03\'")
-
-        self.expect("expression s_b",
-                    startstr="(long) $6 = 2")
-
-        self.runCmd("process continue")
-
-    def set_breakpoint(self, line):
-        lldbutil.run_break_set_by_file_and_line(
-            self, "main.cpp", line, num_expected_locations=1, loc_exact=False)

diff  --git a/lldb/test/API/lang/cpp/static_members/main.cpp b/lldb/test/API/lang/cpp/static_members/main.cpp
index 1503ec6e0ebf6..87ea6aa877472 100644
--- a/lldb/test/API/lang/cpp/static_members/main.cpp
+++ b/lldb/test/API/lang/cpp/static_members/main.cpp
@@ -1,25 +1,20 @@
-struct A
-{
-    short m_a;
-    static long s_b;
-    char m_c;
-    static int s_d;
+struct A {
+  short m_a;
+  static long s_b;
+  static int s_c;
 
-    long access() {
-        return m_a + s_b + m_c + s_d; // breakpoint 2
-    }
+  long access() {
+    return m_a + s_b + s_c; // stop in member function
+  }
 };
 
 long A::s_b = 2;
-int A::s_d = 4;
+int A::s_c = 3;
 
-int main()
-{
-    A my_a;
-    my_a.m_a = 1;
-    my_a.m_c = 3;
+int main() {
+  A my_a;
+  my_a.m_a = 1;
 
-    my_a.access(); // breakpoint 1 
-    return 0;
+  my_a.access(); // stop in main
+  return 0;
 }
-


        


More information about the lldb-commits mailing list