[Lldb-commits] [lldb] 78e17e2 - [lldb] Rewrite TestDiamond and document some bugs.

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 14 11:32:48 PDT 2021


Author: Raphael Isemann
Date: 2021-10-14T20:32:07+02:00
New Revision: 78e17e23aa0fe525d00a2e8f0c7469f9a6b94f40

URL: https://github.com/llvm/llvm-project/commit/78e17e23aa0fe525d00a2e8f0c7469f9a6b94f40
DIFF: https://github.com/llvm/llvm-project/commit/78e17e23aa0fe525d00a2e8f0c7469f9a6b94f40.diff

LOG: [lldb] Rewrite TestDiamond and document some bugs.

Added: 
    lldb/test/API/lang/cpp/diamond/TestCppDiamond.py

Modified: 
    lldb/test/API/lang/cpp/diamond/main.cpp

Removed: 
    lldb/test/API/lang/cpp/diamond/TestDiamond.py


################################################################################
diff  --git a/lldb/test/API/lang/cpp/diamond/TestCppDiamond.py b/lldb/test/API/lang/cpp/diamond/TestCppDiamond.py
new file mode 100644
index 0000000000000..4a561be425775
--- /dev/null
+++ b/lldb/test/API/lang/cpp/diamond/TestCppDiamond.py
@@ -0,0 +1,84 @@
+"""
+Test diamond inheritance.
+"""
+
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test_with_sbvalue(self):
+        """
+        Test that virtual base classes work in when SBValue objects are
+        used to explore the class.
+        """
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "// breakpoint 1", lldb.SBFileSpec("main.cpp"))
+
+        j1 = self.frame().FindVariable("j1")
+        j1_Derived1 = j1.GetChildAtIndex(0)
+        j1_Derived2 = j1.GetChildAtIndex(1)
+        j1_Derived1_VBase = j1_Derived1.GetChildAtIndex(0)
+        j1_Derived2_VBase = j1_Derived2.GetChildAtIndex(0)
+        j1_Derived1_VBase_m_value = j1_Derived1_VBase.GetChildAtIndex(0)
+        j1_Derived2_VBase_m_value = j1_Derived2_VBase.GetChildAtIndex(0)
+
+        self.assertEqual(
+            j1_Derived1_VBase.GetLoadAddress(), j1_Derived2_VBase.GetLoadAddress(),
+            "ensure virtual base class is the same between Derived1 and Derived2")
+        self.assertEqual(j1_Derived1_VBase_m_value.GetValueAsUnsigned(
+            1), j1_Derived2_VBase_m_value.GetValueAsUnsigned(2), "ensure m_value in VBase is the same")
+        self.assertEqual(self.frame().FindVariable("d").GetChildAtIndex(0).GetChildAtIndex(
+            0).GetValueAsUnsigned(0), 12345, "ensure Derived2 from j1 is correct")
+
+        # This reassigns 'd' to point to 'j2'.
+        self.thread().StepOver()
+
+        self.assertEqual(self.frame().FindVariable("d").GetChildAtIndex(0).GetChildAtIndex(
+            0).GetValueAsUnsigned(0), 12346, "ensure Derived2 from j2 is correct")
+
+    @no_debug_info_test
+    def test(self):
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "// breakpoint 1", lldb.SBFileSpec("main.cpp"))
+
+        # All the children of j1.
+        children = [
+            ValueCheck(type="Derived1", children=[
+                ValueCheck(type="VBase", children=[
+                    ValueCheck(type="int", name="m_value", value="12345")
+                ])
+            ]),
+            ValueCheck(type="Derived2", children=[
+                ValueCheck(type="VBase", children=[
+                    ValueCheck(type="int", name="m_value", value="12345")
+                ])
+            ]),
+            ValueCheck(type="long", value="1"),
+        ]
+        # Try using the class with expression evaluator/variable paths.
+        self.expect_expr("j1", result_type="Joiner1", result_children=children)
+        self.expect_var_path("j1", type="Joiner1", children=children)
+
+        # Use the expression evaluator to access the members.
+        self.expect_expr("j1.x", result_type="long", result_value="1")
+        self.expect_expr("j1.m_value", result_type="int", result_value="12345")
+
+        # Use variable paths to access the members.
+        self.expect_var_path("j1.x", type="long", value="1")
+
+    @expectedFailureAll
+    @no_debug_info_test
+    def test(self):
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "// breakpoint 1", lldb.SBFileSpec("main.cpp"))
+        # FIXME: This is completely broken and 'succeeds' with an error that
+        # there is noch such value/member in Joiner1. Move this up to the test
+        # above when fixed.
+        self.expect_var_path("j1.m_value", type="int", value="12345")

diff  --git a/lldb/test/API/lang/cpp/diamond/TestDiamond.py b/lldb/test/API/lang/cpp/diamond/TestDiamond.py
deleted file mode 100644
index a77864bd841ad..0000000000000
--- a/lldb/test/API/lang/cpp/diamond/TestDiamond.py
+++ /dev/null
@@ -1,51 +0,0 @@
-"""
-Tests that bool types work
-"""
-import lldb
-from lldbsuite.test.lldbtest import *
-import lldbsuite.test.lldbutil as lldbutil
-
-
-class CPPTestDiamondInheritance(TestBase):
-
-    mydir = TestBase.compute_mydir(__file__)
-
-    def test_with_run_command(self):
-        """Test that virtual base classes work in when SBValue objects are used to explore the variable value"""
-        self.build()
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
-        self.set_breakpoint(line_number('main.cpp', '// breakpoint 1'))
-        self.set_breakpoint(line_number('main.cpp', '// breakpoint 2'))
-        process = target.LaunchSimple(
-            None, None, self.get_process_working_directory())
-        self.assertTrue(process, PROCESS_IS_VALID)
-        thread = lldbutil.get_stopped_thread(
-            process, lldb.eStopReasonBreakpoint)
-        self.assertIsNotNone(thread)
-        frame = thread.GetFrameAtIndex(0)
-        j1 = frame.FindVariable("j1")
-        j1_Derived1 = j1.GetChildAtIndex(0)
-        j1_Derived2 = j1.GetChildAtIndex(1)
-        j1_Derived1_VBase = j1_Derived1.GetChildAtIndex(0)
-        j1_Derived2_VBase = j1_Derived2.GetChildAtIndex(0)
-        j1_Derived1_VBase_m_value = j1_Derived1_VBase.GetChildAtIndex(0)
-        j1_Derived2_VBase_m_value = j1_Derived2_VBase.GetChildAtIndex(0)
-        self.assertEqual(
-            j1_Derived1_VBase.GetLoadAddress(), j1_Derived2_VBase.GetLoadAddress(),
-            "ensure virtual base class is the same between Derived1 and Derived2")
-        self.assertTrue(j1_Derived1_VBase_m_value.GetValueAsUnsigned(
-            1) == j1_Derived2_VBase_m_value.GetValueAsUnsigned(2), "ensure m_value in VBase is the same")
-        self.assertTrue(frame.FindVariable("d").GetChildAtIndex(0).GetChildAtIndex(
-            0).GetValueAsUnsigned(0) == 12345, "ensure Derived2 from j1 is correct")
-        thread.StepOver()
-        self.assertTrue(frame.FindVariable("d").GetChildAtIndex(0).GetChildAtIndex(
-            0).GetValueAsUnsigned(0) == 12346, "ensure Derived2 from j2 is correct")
-
-    def set_breakpoint(self, line):
-        # Some compilers (for example GCC 4.4.7 and 4.6.1) emit multiple locations for the statement with the ternary
-        # operator in the test program, while others emit only 1.
-        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/diamond/main.cpp b/lldb/test/API/lang/cpp/diamond/main.cpp
index 8f9714d33172c..fdf2f3d326747 100644
--- a/lldb/test/API/lang/cpp/diamond/main.cpp
+++ b/lldb/test/API/lang/cpp/diamond/main.cpp
@@ -1,77 +1,29 @@
-#include <stdio.h>
-
 static int g_next_value = 12345;
 
-class VBase
-{
-public:
-    VBase() : m_value(g_next_value++) {}
-    virtual ~VBase() {}
-    void Print() 
-    {
-        printf("%p: %s\n%p: m_value = 0x%8.8x\n", this, __PRETTY_FUNCTION__, &m_value, m_value);
-    }
-    int m_value;
+struct VBase {
+  VBase() : m_value(g_next_value++) {}
+  virtual ~VBase() {}
+  int m_value;
 };
 
-class Derived1 : public virtual VBase
-{
-public:
-    Derived1() {};
-    void Print ()
-    {
-        printf("%p: %s\n", this, __PRETTY_FUNCTION__);
-        VBase::Print();
-    }
-
+struct Derived1 : public virtual VBase {
 };
 
-class Derived2 : public virtual VBase
-{
-public:
-    Derived2() {};
-    
-    void Print ()
-    {
-        printf("%p: %s\n", this, __PRETTY_FUNCTION__);
-        VBase::Print();
-    }
+struct Derived2 : public virtual VBase {
 };
 
-class Joiner1 : public Derived1, public Derived2
-{
-public:
-    Joiner1() : 
-        m_joiner1(3456), 
-        m_joiner2(6789) {}
-    void Print ()
-    {
-        printf("%p: %s \n%p: m_joiner1 = 0x%8.8x\n%p: m_joiner2 = 0x%8.8x\n",
-               this,
-               __PRETTY_FUNCTION__,
-               &m_joiner1,
-               m_joiner1,
-               &m_joiner2,
-               m_joiner2);
-        Derived1::Print();
-        Derived2::Print();
-    }
-    int m_joiner1;
-    int m_joiner2;
+struct Joiner1 : public Derived1, public Derived2 {
+  long x = 1;
 };
 
-class Joiner2 : public Derived2
-{
-    int m_stuff[32];
+struct Joiner2 : public Derived2 {
+  long y = 2;
 };
 
-int main(int argc, const char * argv[])
-{
-    Joiner1 j1;
-    Joiner2 j2;
-    j1.Print();
-    j2.Print();
-    Derived2 *d = &j1;
-    d = &j2;  // breakpoint 1
-    return 0; // breakpoint 2
+int main(int argc, const char *argv[]) {
+  Joiner1 j1;
+  Joiner2 j2;
+  Derived2 *d = &j1;
+  d = &j2;  // breakpoint 1
+  return 0; // breakpoint 2
 }


        


More information about the lldb-commits mailing list