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