1""" 2Test the iteration protocol for frame registers. 3""" 4 5import os, time 6import re 7import unittest2 8import lldb 9from lldbtest import * 10 11class RegistersIteratorTestCase(TestBase): 12 13 mydir = os.path.join("python_api", "lldbutil", "iter") 14 15 def setUp(self): 16 # Call super's setUp(). 17 TestBase.setUp(self) 18 # Find the line number to break inside main(). 19 self.line1 = line_number('main.cpp', '// Set break point at this line.') 20 21 @expectedFailureFreeBSD # llvm.org/pr14600 - Exception state registers not supported on FreeBSD 22 @expectedFailureLinux # llvm.org/pr14600 - Exception state registers not supported on Linux 23 @python_api_test 24 def test_iter_registers(self): 25 """Test iterator works correctly for lldbutil.iter_registers().""" 26 self.buildDefault() 27 self.iter_registers() 28 29 def iter_registers(self): 30 exe = os.path.join(os.getcwd(), "a.out") 31 32 target = self.dbg.CreateTarget(exe) 33 self.assertTrue(target, VALID_TARGET) 34 35 breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line1) 36 self.assertTrue(breakpoint, VALID_BREAKPOINT) 37 38 # Now launch the process, and do not stop at entry point. 39 process = target.LaunchSimple(None, None, os.getcwd()) 40 41 if not process: 42 self.fail("SBTarget.LaunchProcess() failed") 43 44 import lldbutil 45 for thread in process: 46 if thread.GetStopReason() == lldb.eStopReasonBreakpoint: 47 for frame in thread: 48 # Dump the registers of this frame using lldbutil.get_GPRs() and friends. 49 if self.TraceOn(): 50 print frame 51 52 REGs = lldbutil.get_GPRs(frame) 53 num = len(REGs) 54 if self.TraceOn(): 55 print "\nNumber of general purpose registers: %d" % num 56 for reg in REGs: 57 self.assertTrue(reg) 58 if self.TraceOn(): 59 print "%s => %s" % (reg.GetName(), reg.GetValue()) 60 61 REGs = lldbutil.get_FPRs(frame) 62 num = len(REGs) 63 if self.TraceOn(): 64 print "\nNumber of floating point registers: %d" % num 65 for reg in REGs: 66 self.assertTrue(reg) 67 if self.TraceOn(): 68 print "%s => %s" % (reg.GetName(), reg.GetValue()) 69 70 REGs = lldbutil.get_ESRs(frame) 71 num = len(REGs) 72 if self.TraceOn(): 73 print "\nNumber of exception state registers: %d" % num 74 for reg in REGs: 75 self.assertTrue(reg) 76 if self.TraceOn(): 77 print "%s => %s" % (reg.GetName(), reg.GetValue()) 78 79 # And these should also work. 80 for kind in ["General Purpose Registers", 81 "Floating Point Registers", 82 "Exception State Registers"]: 83 REGs = lldbutil.get_registers(frame, kind) 84 self.assertTrue(REGs) 85 86 # We've finished dumping the registers for frame #0. 87 break 88 89 90if __name__ == '__main__': 91 import atexit 92 lldb.SBDebugger.Initialize() 93 atexit.register(lambda: lldb.SBDebugger.Terminate()) 94 unittest2.main() 95