1 """Disassemble lldb's Driver::MainLoop() functions comparing Xcode 4.1 vs. 4.2's gdb.""" 2 3 import os, sys 4 import unittest2 5 import lldb 6 import pexpect 7 from lldbbench import * 8 9 class XCode41Vs42GDBDisassembly(BenchBase): 10 11 mydir = os.path.join("benchmarks", "disassembly") 12 13 def setUp(self): 14 BenchBase.setUp(self) 15 self.gdb_41_exe = '/Xcode41/usr/bin/gdb' 16 self.gdb_42_exe = '/Developer/usr/bin/gdb' 17 self.exe = self.lldbHere 18 self.function = 'Driver::MainLoop()' 19 self.gdb_41_avg = None 20 self.gdb_42_avg = None 21 self.count = lldb.bmIterationCount 22 if self.count <= 0: 23 self.count = 5 24 25 @benchmarks_test 26 def test_run_41_then_42(self): 27 """Test disassembly on a large function with 4.1 vs. 4.2's gdb.""" 28 print 29 self.run_gdb_disassembly(self.gdb_41_exe, self.exe, self.function, self.count) 30 print "4.1 gdb benchmark:", self.stopwatch 31 self.gdb_41_avg = self.stopwatch.avg() 32 self.run_gdb_disassembly(self.gdb_42_exe, self.exe, self.function, self.count) 33 print "4.2 gdb benchmark:", self.stopwatch 34 self.gdb_42_avg = self.stopwatch.avg() 35 print "gdb_42_avg/gdb_41_avg: %f" % (self.gdb_42_avg/self.gdb_41_avg) 36 37 @benchmarks_test 38 def test_run_42_then_41(self): 39 """Test disassembly on a large function with 4.1 vs. 4.2's gdb.""" 40 print 41 self.run_gdb_disassembly(self.gdb_42_exe, self.exe, self.function, self.count) 42 print "4.2 gdb benchmark:", self.stopwatch 43 self.gdb_42_avg = self.stopwatch.avg() 44 self.run_gdb_disassembly(self.gdb_41_exe, self.exe, self.function, self.count) 45 print "4.1 gdb benchmark:", self.stopwatch 46 self.gdb_41_avg = self.stopwatch.avg() 47 print "gdb_42_avg/gdb_41_avg: %f" % (self.gdb_42_avg/self.gdb_41_avg) 48 49 def run_gdb_disassembly(self, gdb_exe_path, exe, function, count): 50 # Set self.child_prompt, which is "(gdb) ". 51 self.child_prompt = '(gdb) ' 52 prompt = self.child_prompt 53 54 # So that the child gets torn down after the test. 55 self.child = pexpect.spawn('%s --nx %s' % (gdb_exe_path, exe)) 56 child = self.child 57 58 # Turn on logging for what the child sends back. 59 if self.TraceOn(): 60 child.logfile_read = sys.stdout 61 62 child.expect_exact(prompt) 63 child.sendline('break %s' % function) 64 child.expect_exact(prompt) 65 child.sendline('run') 66 child.expect_exact(prompt) 67 68 # Reset the stopwatch now. 69 self.stopwatch.reset() 70 for i in range(count): 71 with self.stopwatch: 72 # Disassemble the function. 73 child.sendline('disassemble') 74 child.expect_exact(prompt) 75 child.sendline('next') 76 child.expect_exact(prompt) 77 78 child.sendline('quit') 79 child.expect_exact('The program is running. Exit anyway?') 80 child.sendline('y') 81 try: 82 self.child.expect(pexpect.EOF) 83 except: 84 pass 85 86 if self.TraceOn(): 87 print "gdb disassembly benchmark:", str(self.stopwatch) 88 self.child = None 89 90 91 if __name__ == '__main__': 92 import atexit 93 lldb.SBDebugger.Initialize() 94 atexit.register(lambda: lldb.SBDebugger.Terminate()) 95 unittest2.main() 96