1"""
2Set the contents of variables and registers using raw data
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import lldbutil
10
11@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
12class SetDataTestCase(TestBase):
13
14    mydir = os.path.join("functionalities", "set-data")
15
16    @dsym_test
17    def test_set_data_dsym(self):
18        """Test setting the contents of variables and registers using raw data."""
19        self.buildDsym()
20        self.setData()
21
22    def setData(self):
23        """Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'."""
24        exe = os.path.join(os.getcwd(), "a.out")
25        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
26
27        self.runCmd("br s -p First");
28        self.runCmd("br s -p Second");
29
30        self.runCmd("run", RUN_SUCCEEDED)
31
32        self.expect("p myFoo.x", VARIABLES_DISPLAYED_CORRECTLY,
33            substrs = ['2'])
34
35        process = self.dbg.GetSelectedTarget().GetProcess()
36        frame = process.GetSelectedThread().GetFrameAtIndex(0)
37
38        x = frame.FindVariable("myFoo").GetChildMemberWithName("x")
39
40        my_data = lldb.SBData.CreateDataFromSInt32Array(lldb.eByteOrderLittle, 8, [4])
41        err = lldb.SBError()
42
43        self.assertTrue (x.SetData(my_data, err))
44
45        self.runCmd("continue")
46
47        self.expect("p myFoo.x", VARIABLES_DISPLAYED_CORRECTLY,
48            substrs = ['4'])
49
50        frame = process.GetSelectedThread().GetFrameAtIndex(0)
51
52        x = frame.FindVariable("string")
53
54        if process.GetAddressByteSize() == 8:
55            my_data = lldb.SBData.CreateDataFromUInt64Array(process.GetByteOrder(), 8, [0])
56        else:
57            my_data = lldb.SBData.CreateDataFromUInt32Array(process.GetByteOrder(), 4, [0])
58
59        err = lldb.SBError()
60
61        self.assertTrue (x.SetData(my_data, err))
62
63        self.expect("fr var -d run-target string", VARIABLES_DISPLAYED_CORRECTLY,
64            substrs = ['NSString *', 'nil'])
65
66if __name__ == '__main__':
67    import atexit
68    lldb.SBDebugger.Initialize()
69    atexit.register(lambda: lldb.SBDebugger.Terminate())
70    unittest2.main()
71