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