2 from lldbsuite
.test
.lldbtest
import *
3 from lldbsuite
.test
.decorators
import *
4 from lldbsuite
.test
.gdbclientutils
import *
5 from lldbsuite
.test
.lldbgdbclient
import GDBRemoteTestBase
8 class TestMemoryRegionDirtyPages(GDBRemoteTestBase
):
9 @skipIfXmlSupportMissing
11 class MyResponder(MockGDBServerResponder
):
13 return "ptrsize:8;endian:little;vm-page-size:4096;"
15 def qMemoryRegionInfo(self
, addr
):
17 return "start:0;size:100000000;"
18 if addr
== 0x100000000:
19 return "start:100000000;size:4000;permissions:rx;dirty-pages:;"
20 if addr
== 0x100004000:
22 "start:100004000;size:4000;permissions:r;dirty-pages:100004000;"
24 if addr
== 0x1000A2000:
25 return "start:1000a2000;size:5000;permissions:r;dirty-pages:1000a2000,1000a3000,1000a4000,1000a5000,1000a6000;"
27 self
.server
.responder
= MyResponder()
28 target
= self
.dbg
.CreateTarget("")
30 self
.runCmd("log enable gdb-remote packets")
31 self
.addTearDownHook(lambda: self
.runCmd("log disable gdb-remote packets"))
32 process
= self
.connect(target
)
34 # A memory region where we don't know anything about dirty pages
35 region
= lldb
.SBMemoryRegionInfo()
36 err
= process
.GetMemoryRegionInfo(0, region
)
37 self
.assertSuccess(err
)
38 self
.assertFalse(region
.HasDirtyMemoryPageList())
39 self
.assertEqual(region
.GetNumDirtyPages(), 0)
42 # A memory region with dirty page information -- and zero dirty pages
43 err
= process
.GetMemoryRegionInfo(0x100000000, region
)
44 self
.assertSuccess(err
)
45 self
.assertTrue(region
.HasDirtyMemoryPageList())
46 self
.assertEqual(region
.GetNumDirtyPages(), 0)
47 self
.assertEqual(region
.GetPageSize(), 4096)
50 # A memory region with one dirty page
51 err
= process
.GetMemoryRegionInfo(0x100004000, region
)
52 self
.assertSuccess(err
)
53 self
.assertTrue(region
.HasDirtyMemoryPageList())
54 self
.assertEqual(region
.GetNumDirtyPages(), 1)
55 self
.assertEqual(region
.GetDirtyPageAddressAtIndex(0), 0x100004000)
58 # A memory region with multple dirty pages
59 err
= process
.GetMemoryRegionInfo(0x1000A2000, region
)
60 self
.assertSuccess(err
)
61 self
.assertTrue(region
.HasDirtyMemoryPageList())
62 self
.assertEqual(region
.GetNumDirtyPages(), 5)
63 self
.assertEqual(region
.GetDirtyPageAddressAtIndex(4), 0x1000A6000)