]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_in_delayslot/TestAvoidBreakpointInDelaySlot.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / breakpoint / breakpoint_in_delayslot / TestAvoidBreakpointInDelaySlot.py
1 """
2 Test specific to MIPS 
3 """
4
5 from __future__ import print_function
6
7 import os, time
8 import re
9 import unittest2
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15 class AvoidBreakpointInDelaySlotAPITestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     @skipIf(archs=no_match(re.compile('mips*')))
20     def test(self):
21         self.build()
22         exe = os.path.join(os.getcwd(), "a.out")
23         self.expect("file " + exe,
24                     patterns = [ "Current executable set to .*a.out.*" ])
25         
26         # Create a target by the debugger.
27         target = self.dbg.CreateTarget(exe)
28         self.assertTrue(target, VALID_TARGET)
29
30         breakpoint = target.BreakpointCreateByName('main', 'a.out')
31         self.assertTrue(breakpoint and
32                         breakpoint.GetNumLocations() == 1,
33                         VALID_BREAKPOINT)
34
35         # Now launch the process, and do not stop at entry point.
36         process = target.LaunchSimple (None, None, self.get_process_working_directory())
37         self.assertTrue(process, PROCESS_IS_VALID)
38
39         list = target.FindFunctions('foo', lldb.eFunctionNameTypeAuto)
40         self.assertTrue(list.GetSize() == 1)
41         sc = list.GetContextAtIndex(0)
42         self.assertTrue(sc.GetSymbol().GetName() == "foo")
43         function = sc.GetFunction()
44         self.assertTrue(function)
45         self.function(function, target)
46
47     def function (self, function, target):
48         """Iterate over instructions in function and place a breakpoint on delay slot instruction"""
49         # Get the list of all instructions in the function
50         insts = function.GetInstructions(target)
51         print(insts)
52         i = 0
53         for inst in insts:
54             if (inst.HasDelaySlot()):
55                 # Remember the address of branch instruction.
56                 branchinstaddress = inst.GetAddress().GetLoadAddress(target)
57
58                 # Get next instruction i.e delay slot instruction.
59                 delayinst = insts.GetInstructionAtIndex(i+1)
60                 delayinstaddr = delayinst.GetAddress().GetLoadAddress(target)
61
62                 # Set breakpoint on delay slot instruction
63                 breakpoint = target.BreakpointCreateByAddress(delayinstaddr)
64
65                 # Verify the breakpoint.
66                 self.assertTrue(breakpoint and
67                                 breakpoint.GetNumLocations() == 1,
68                                 VALID_BREAKPOINT)
69                 # Get the location from breakpoint
70                 location = breakpoint.GetLocationAtIndex(0)
71
72                 # Get the address where breakpoint is actually set.
73                 bpaddr = location.GetLoadAddress()
74                 
75                 # Breakpoint address should be adjusted to the address of branch instruction.
76                 self.assertTrue(branchinstaddress ==  bpaddr)
77                 i += 1
78             else:
79                 i += 1
80
81 if __name__ == '__main__':
82     import atexit
83     lldb.SBDebugger.Initialize()
84     atexit.register(lambda: lldb.SBDebugger.Terminate())
85     unittest2.main()