xref: /llvm-project/lldb/test/API/commands/expression/memory-allocation/TestMemoryAllocSettings.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test changing setting for expression memory allocation.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class TestMemoryAllocSettings(TestBase):
12    def test(self):
13        """Test changing settings for expression memory allocation."""
14        self.build()
15        target = self.createTestTarget()
16
17        self.log_file = self.getBuildArtifact("log-expr.txt")
18
19        self.runCmd("settings set target.expr-alloc-address 0xdead0000")
20        self.runCmd("settings set target.expr-alloc-size 10000")
21        self.runCmd("settings set target.expr-alloc-align 0x1000")
22
23        self.runCmd("log enable lldb expr -f " + self.log_file)
24        self.runCmd("expression -- int foo; &foo")
25
26        self.assertTrue(os.path.isfile(self.log_file))
27        with open(self.log_file, "r") as f:
28            log = f.read()
29
30        alloc0 = re.search("^.*IRMemoryMap::Malloc.+?0xdead0000.*$", log, re.MULTILINE)
31        # Malloc adds additional bytes to allocation size, hence 10007
32        alloc1 = re.search(
33            "^.*IRMemoryMap::Malloc\s*?\(10007.+?0xdead1000.*$", log, re.MULTILINE
34        )
35        self.assertTrue(alloc0, "Couldn't find an allocation at a given address.")
36        self.assertTrue(
37            alloc1, "Couldn't find an allocation of a given size at a given address."
38        )
39