xref: /llvm-project/lldb/test/API/python_api/value_var_update/TestValueVarUpdate.py (revision 05d7d6949c7cd3f1566d4c8394fa59160a7ffd05)
1"""Test SBValue::GetValueDidChange"""
2
3
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class ValueVarUpdateTestCase(TestBase):
12
13    mydir = TestBase.compute_mydir(__file__)
14
15    def test_with_process_launch_api(self):
16        """Test SBValue::GetValueDidChange"""
17        # Get the full path to our executable to be attached/debugged.
18        exe = self.getBuildArtifact(self.testMethodName)
19        d = {'EXE': exe}
20        self.build(dictionary=d)
21        self.setTearDownCleanup(dictionary=d)
22        target = self.dbg.CreateTarget(exe)
23
24        breakpoint = target.BreakpointCreateBySourceRegex(
25            "break here", lldb.SBFileSpec("main.c"))
26
27        self.runCmd("run", RUN_SUCCEEDED)
28
29        # The stop reason of the thread should be breakpoint.
30        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
31                    substrs=['stopped',
32                             'stop reason = breakpoint'])
33
34        i = self.frame().FindVariable("i")
35        i_val = i.GetValueAsUnsigned(0)
36        c = self.frame().FindVariable("c")
37
38        # Update any values from the SBValue objects so we can ask them if they
39        # changed after a continue
40        i.GetValueDidChange()
41        c.GetChildAtIndex(1).GetValueDidChange()
42        c.GetChildAtIndex(0).GetChildAtIndex(0).GetValueDidChange()
43
44        if self.TraceOn():
45            self.runCmd("frame variable")
46
47        self.runCmd("continue")
48
49        if self.TraceOn():
50            self.runCmd("frame variable")
51
52        self.assertTrue(
53            i_val != i.GetValueAsUnsigned(0),
54            "GetValue() is saying a lie")
55        self.assertTrue(
56            i.GetValueDidChange(),
57            "GetValueDidChange() is saying a lie")
58
59        # Check complex type
60        self.assertTrue(c.GetChildAtIndex(0).GetChildAtIndex(0).GetValueDidChange(
61        ) and not c.GetChildAtIndex(1).GetValueDidChange(), "GetValueDidChange() is saying a lie")
62