1 """Test lldb's stepping speed.""" 2 3 import os, sys 4 import unittest2 5 import lldb 6 import pexpect 7 from lldbbench import * 8 9 class SteppingSpeedBench(BenchBase): 10 11 mydir = os.path.join("benchmarks", "stepping") 12 13 def setUp(self): 14 BenchBase.setUp(self) 15 if lldb.bmExecutable: 16 self.exe = lldb.bmExecutable 17 else: 18 self.exe = self.lldbHere 19 if lldb.bmBreakpointSpec: 20 self.break_spec = lldb.bmBreakpointSpec 21 else: 22 self.break_spec = '-n main' 23 24 self.count = lldb.bmIterationCount 25 if self.count <= 0: 26 self.count = 50 27 28 #print "self.exe=%s" % self.exe 29 #print "self.break_spec=%s" % self.break_spec 30 31 @benchmarks_test 32 def test_run_lldb_steppings(self): 33 """Test lldb steppings on a large executable.""" 34 print 35 self.run_lldb_steppings(self.exe, self.break_spec, self.count) 36 print "lldb stepping benchmark:", self.stopwatch 37 38 def run_lldb_steppings(self, exe, break_spec, count): 39 # Set self.child_prompt, which is "(lldb) ". 40 self.child_prompt = '(lldb) ' 41 prompt = self.child_prompt 42 43 # So that the child gets torn down after the test. 44 self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe)) 45 child = self.child 46 47 # Turn on logging for what the child sends back. 48 if self.TraceOn(): 49 child.logfile_read = sys.stdout 50 51 child.expect_exact(prompt) 52 child.sendline('breakpoint set %s' % break_spec) 53 child.expect_exact(prompt) 54 child.sendline('run') 55 child.expect_exact(prompt) 56 57 # Reset the stopwatch now. 58 self.stopwatch.reset() 59 for i in range(count): 60 with self.stopwatch: 61 # Disassemble the function. 62 child.sendline('next') # Aka 'thread step-over'. 63 child.expect_exact(prompt) 64 65 child.sendline('quit') 66 try: 67 self.child.expect(pexpect.EOF) 68 except: 69 pass 70 71 self.child = None 72 73 74 if __name__ == '__main__': 75 import atexit 76 lldb.SBDebugger.Initialize() 77 atexit.register(lambda: lldb.SBDebugger.Terminate()) 78 unittest2.main() 79