• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Set the contents of variables and registers using raw data
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class SetDataTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    @add_test_categories(["objc"])
18    def test_set_data(self):
19        """Test setting the contents of variables and registers using raw data."""
20        self.build()
21        exe = self.getBuildArtifact("a.out")
22        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
23
24        self.runCmd("br s -p First")
25        self.runCmd("br s -p Second")
26
27        self.runCmd("run", RUN_SUCCEEDED)
28
29        self.expect("p myFoo.x", VARIABLES_DISPLAYED_CORRECTLY,
30                    substrs=['2'])
31
32        process = self.dbg.GetSelectedTarget().GetProcess()
33        frame = process.GetSelectedThread().GetFrameAtIndex(0)
34
35        x = frame.FindVariable("myFoo").GetChildMemberWithName("x")
36
37        my_data = lldb.SBData.CreateDataFromSInt32Array(
38            lldb.eByteOrderLittle, 8, [4])
39        err = lldb.SBError()
40
41        self.assertTrue(x.SetData(my_data, err))
42
43        self.runCmd("continue")
44
45        self.expect("p myFoo.x", VARIABLES_DISPLAYED_CORRECTLY,
46                    substrs=['4'])
47
48        frame = process.GetSelectedThread().GetFrameAtIndex(0)
49
50        x = frame.FindVariable("string")
51
52        if process.GetAddressByteSize() == 8:
53            my_data = lldb.SBData.CreateDataFromUInt64Array(
54                process.GetByteOrder(), 8, [0])
55        else:
56            my_data = lldb.SBData.CreateDataFromUInt32Array(
57                process.GetByteOrder(), 4, [0])
58
59        err = lldb.SBError()
60
61        self.assertTrue(x.SetData(my_data, err))
62
63        self.expect(
64            "fr var -d run-target string",
65            VARIABLES_DISPLAYED_CORRECTLY,
66            substrs=[
67                'NSString *',
68                'nil'])
69