TestGDBRemoteLoad.py
2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
from gdbclientutils import *
class TestGDBRemoteLoad(GDBRemoteTestBase):
def test_module_load_address(self):
"""Test that setting the load address of a module uses virtual addresses"""
target = self.createTarget("a.yaml")
process = self.connect(target)
module = target.GetModuleAtIndex(0)
self.assertTrue(module.IsValid())
self.assertTrue(target.SetModuleLoadAddress(module, 0).Success())
address = target.ResolveLoadAddress(0x2001)
self.assertTrue(address.IsValid())
self.assertEqual(".data", address.GetSection().GetName())
@skipIfReproducer # Packet log is not populated during replay.
def test_ram_load(self):
"""Test loading an object file to a target's ram"""
target = self.createTarget("a.yaml")
process = self.connect(target)
self.dbg.HandleCommand("target modules load -l -s0")
self.assertPacketLogContains([
"M1000,4:c3c3c3c3",
"M1004,2:3232"
])
@skipIfXmlSupportMissing
@skipIfReproducer # Packet log is not populated during replay.
def test_flash_load(self):
"""Test loading an object file to a target's flash memory"""
class Responder(MockGDBServerResponder):
def qSupported(self, client_supported):
return "PacketSize=3fff;QStartNoAckMode+;qXfer:memory-map:read+"
def qXferRead(self, obj, annex, offset, length):
if obj == "memory-map":
return (self.MEMORY_MAP[offset:offset + length],
offset + length < len(self.MEMORY_MAP))
return None, False
def other(self, packet):
if packet[0:11] == "vFlashErase":
return "OK"
if packet[0:11] == "vFlashWrite":
return "OK"
if packet == "vFlashDone":
return "OK"
return ""
MEMORY_MAP = """<?xml version="1.0"?>
<memory-map>
<memory type="ram" start="0x0" length="0x1000"/>
<memory type="flash" start="0x1000" length="0x1000">
<property name="blocksize">0x100</property>
</memory>
<memory type="ram" start="0x2000" length="0x1D400"/>
</memory-map>
"""
self.server.responder = Responder()
target = self.createTarget("a.yaml")
process = self.connect(target)
self.dbg.HandleCommand("target modules load -l -s0")
self.assertPacketLogContains([
"vFlashErase:1000,100",
"vFlashWrite:1000:\xc3\xc3\xc3\xc3",
"vFlashWrite:1004:\x32\x32",
"vFlashDone"
])