1"""
2Test that dynamic values update their child count correctly
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class DynamicValueChildCountTestCase(TestBase):
14
15    def setUp(self):
16        # Call super's setUp().
17        TestBase.setUp(self)
18
19        # Find the line number to break for main.c.
20
21        self.main_third_call_line = line_number(
22            'pass-to-base.cpp', '// Break here and check b has 0 children')
23        self.main_fourth_call_line = line_number(
24            'pass-to-base.cpp', '// Break here and check b still has 0 children')
25        self.main_fifth_call_line = line_number(
26            'pass-to-base.cpp', '// Break here and check b has one child now')
27        self.main_sixth_call_line = line_number(
28            'pass-to-base.cpp', '// Break here and check b has 0 children again')
29
30    @add_test_categories(['pyapi'])
31    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24663")
32    def test_get_dynamic_vals(self):
33        """Test fetching C++ dynamic values from pointers & references."""
34        """Get argument vals for the call stack when stopped on a breakpoint."""
35        self.build()
36        exe = self.getBuildArtifact("a.out")
37
38        # Create a target from the debugger.
39
40        target = self.dbg.CreateTarget(exe)
41        self.assertTrue(target, VALID_TARGET)
42
43        # Set up our breakpoints:
44
45        third_call_bpt = target.BreakpointCreateByLocation(
46            'pass-to-base.cpp', self.main_third_call_line)
47        self.assertTrue(third_call_bpt,
48                        VALID_BREAKPOINT)
49        fourth_call_bpt = target.BreakpointCreateByLocation(
50            'pass-to-base.cpp', self.main_fourth_call_line)
51        self.assertTrue(fourth_call_bpt,
52                        VALID_BREAKPOINT)
53        fifth_call_bpt = target.BreakpointCreateByLocation(
54            'pass-to-base.cpp', self.main_fifth_call_line)
55        self.assertTrue(fifth_call_bpt,
56                        VALID_BREAKPOINT)
57        sixth_call_bpt = target.BreakpointCreateByLocation(
58            'pass-to-base.cpp', self.main_sixth_call_line)
59        self.assertTrue(sixth_call_bpt,
60                        VALID_BREAKPOINT)
61
62        # Now launch the process, and do not stop at the entry point.
63        process = target.LaunchSimple(
64            None, None, self.get_process_working_directory())
65
66        self.assertState(process.GetState(), lldb.eStateStopped,
67                         PROCESS_STOPPED)
68
69        b = self.frame().FindVariable("b").GetDynamicValue(lldb.eDynamicCanRunTarget)
70        self.assertEquals(b.GetNumChildren(), 0, "b has 0 children")
71        self.runCmd("continue")
72        self.assertEquals(b.GetNumChildren(), 0, "b still has 0 children")
73        self.runCmd("continue")
74        self.assertNotEqual(b.GetNumChildren(), 0, "b now has 1 child")
75        self.runCmd("continue")
76        self.assertEqual(
77            b.GetNumChildren(), 0,
78            "b didn't go back to 0 children")
79