xref: /llvm-project/lldb/test/API/python_api/value/empty_class/TestValueAPIEmptyClass.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1import lldb
2from lldbsuite.test.decorators import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5
6
7class ValueAPIEmptyClassTestCase(TestBase):
8    def test(self):
9        self.build()
10        exe = self.getBuildArtifact("a.out")
11        line = line_number("main.cpp", "// Break at this line")
12
13        # Create a target by the debugger.
14        target = self.dbg.CreateTarget(exe)
15        self.assertTrue(target, VALID_TARGET)
16
17        # Create the breakpoint inside function 'main'.
18        breakpoint = target.BreakpointCreateByLocation("main.cpp", line)
19        self.assertTrue(breakpoint, VALID_BREAKPOINT)
20
21        # Now launch the process, and do not stop at entry point.
22        process = target.LaunchSimple(None, None, self.get_process_working_directory())
23        self.assertTrue(process, PROCESS_IS_VALID)
24
25        # Get Frame #0.
26        self.assertState(process.GetState(), lldb.eStateStopped)
27        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
28        self.assertTrue(
29            thread.IsValid(),
30            "There should be a thread stopped due to breakpoint condition",
31        )
32        frame0 = thread.GetFrameAtIndex(0)
33
34        # Verify that we can access to a frame variable with an empty class type
35        e = frame0.FindVariable("e")
36        self.assertTrue(e.IsValid(), VALID_VARIABLE)
37        self.DebugSBValue(e)
38        self.assertEqual(e.GetNumChildren(), 0)
39
40        # Verify that we can acces to a frame variable what is a pointer to an
41        # empty class
42        ep = frame0.FindVariable("ep")
43        self.assertTrue(ep.IsValid(), VALID_VARIABLE)
44        self.DebugSBValue(ep)
45
46        # Verify that we can dereference a pointer to an empty class
47        epd = ep.Dereference()
48        self.assertTrue(epd.IsValid(), VALID_VARIABLE)
49        self.DebugSBValue(epd)
50        self.assertEqual(epd.GetNumChildren(), 0)
51