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
7 # This test ensures that LLDB correctly handles packets sent by MSPDebug.
8 # https://github.com/dlbeer/mspdebug
11 class MyResponder(MockGDBServerResponder
):
12 def qSupported(self
, client_supported
):
13 return "PacketSize=4000"
15 def setBreakpoint(self
, packet
):
19 # Registers 3 to 15 are empty
20 regs3to15
= "".join("%02x:%s;" % (i
, "00000000") for i
in range(3, 16))
21 yield "T0500:00050000;01:00000000;02:00000000;" + regs3to15
22 yield "T0500:10050000;01:baff0000;02:05000000;" + regs3to15
23 yield "T0500:16050000;01:baff0000;02:05000000;" + regs3to15
25 stopPacket
= stopPackets()
28 return next(self
.stopPacket
)
31 return self
.haltReason()
34 def readMemory(self
, addr
, length
):
39 + "3140c0ff0c43b0121c05b01281010000b240d2043c051c423c0530413180020081430000b01210053150020030411c4330413c402a0030410c433041"
44 return ("ff" * 442) + "280500000a05" + ("ff" * 62) + "0005"
47 class TestMSP430MSPDebug(GDBRemoteTestBase
):
48 @skipIfLLVMTargetMissing("MSP430")
51 Test LLDB's MSP430 functionality.
53 target
= self
.createTarget("msp430.yaml")
54 self
.server
.responder
= MyResponder()
57 self
.runCmd("log enable gdb-remote packets")
58 self
.addTearDownHook(lambda: self
.runCmd("log disable gdb-remote packets"))
60 process
= self
.connect(target
)
61 lldbutil
.expect_state_changes(
62 self
, self
.dbg
.GetListener(), process
, [lldb
.eStateStopped
]
64 num_threads
= len(process
.threads
)
65 self
.assertEqual(num_threads
, 1, "Only one thread")
66 thread
= process
.GetThreadAtIndex(0)
68 # Test if a breakpoint can be set
69 bp
= target
.BreakpointCreateByName("func")
70 self
.assertTrue(bp
.IsValid())
72 self
.assertTrue(bp
.IsEnabled())
74 # Test if the breakpoint address is resolved correctly
75 self
.assertEqual(bp
.GetNumLocations(), 1, "Only one location")
76 bp_loc
= bp
.GetLocationAtIndex(0)
78 bp_loc
.GetAddress().GetLoadAddress(target
), 0x510, "Address of main"
81 # Test if the process stops at the breakpoint
83 self
.assertStopReason(
84 thread
.GetStopReason(), lldb
.eStopReasonBreakpoint
, "Hit a breakpoint"
87 # Check if disassembler works and the current function is "func"
88 func
= thread
.GetFrameAtIndex(0).GetFunction()
89 insts
= func
.GetInstructions(target
)
90 inst
= insts
.GetInstructionAtIndex(0)
91 self
.assertEqual(inst
.GetMnemonic(target
), "mov")
92 self
.assertEqual(inst
.GetOperands(target
), "#1234, &1340")
94 # Test if thread can step a single instruction
95 thread
.StepInstruction(False)
97 thread
.GetFrameAtIndex(0).GetPCAddress().GetLoadAddress(target
),
99 "Address of the next instruction",
102 # Test if registers are being set correctly
103 registerSet
= thread
.GetFrameAtIndex(0).GetRegisters().GetValueAtIndex(0)
122 for reg
in registerSet
:
123 self
.assertEqual(reg
.GetValueAsUnsigned(), reg_val_dict
[reg
.GetName()])
125 # Check if backtracing works:
126 self
.assertGreaterEqual(len(thread
.frames
), 3)
127 crt0_addr
= thread
.GetFrameAtIndex(2).GetPCAddress().GetLoadAddress(target
)
128 self
.assertEqual(crt0_addr
, 0x50A)