1 """Disassemble lldb's Driver::MainLoop() functions comparing lldb against gdb."""
3 from __future__ import print_function
9 from lldbsuite.test import configuration
10 from lldbsuite.test.lldbbench import *
13 """Returns true if fpath is an executable."""
14 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
16 class DisassembleDriverMainLoop(BenchBase):
18 mydir = TestBase.compute_mydir(__file__)
22 Note that lldbtest_config.lldbExec can be specified with the LLDB_EXEC env variable (see
23 dotest.py), and gdbExec can be specified with the GDB_EXEC env variable.
24 This provides a flexibility in specifying different versions of gdb for
28 # If env var GDB_EXEC is specified, use it; otherwise, use gdb in your
30 if "GDB_EXEC" in os.environ and is_exe(os.environ["GDB_EXEC"]):
31 self.gdbExec = os.environ["GDB_EXEC"]
35 self.exe = lldbtest_config.lldbExec
36 self.function = 'Driver::MainLoop()'
43 @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
44 def test_run_lldb_then_gdb(self):
45 """Test disassembly on a large function with lldb vs. gdb."""
47 print("lldb path: %s" % lldbtest_config.lldbExec)
48 print("gdb path: %s" % self.gdbExec)
51 self.run_lldb_disassembly(self.exe, self.function, self.count)
52 print("lldb benchmark:", self.stopwatch)
53 self.run_gdb_disassembly(self.exe, self.function, self.count)
54 print("gdb benchmark:", self.stopwatch)
55 print("lldb_avg/gdb_avg: %f" % (self.lldb_avg/self.gdb_avg))
59 @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
60 def test_run_gdb_then_lldb(self):
61 """Test disassembly on a large function with lldb vs. gdb."""
63 print("lldb path: %s" % lldbtest_config.lldbExec)
64 print("gdb path: %s" % self.gdbExec)
67 self.run_gdb_disassembly(self.exe, self.function, self.count)
68 print("gdb benchmark:", self.stopwatch)
69 self.run_lldb_disassembly(self.exe, self.function, self.count)
70 print("lldb benchmark:", self.stopwatch)
71 print("lldb_avg/gdb_avg: %f" % (self.lldb_avg/self.gdb_avg))
73 def run_lldb_disassembly(self, exe, function, count):
75 # Set self.child_prompt, which is "(lldb) ".
76 self.child_prompt = '(lldb) '
77 prompt = self.child_prompt
79 # So that the child gets torn down after the test.
80 self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
83 # Turn on logging for what the child sends back.
85 child.logfile_read = sys.stdout
87 child.expect_exact(prompt)
88 child.sendline('breakpoint set -F %s' % function)
89 child.expect_exact(prompt)
91 child.expect_exact(prompt)
93 # Reset the stopwatch now.
94 self.stopwatch.reset()
95 for i in range(count):
97 # Disassemble the function.
98 child.sendline('disassemble -f')
99 child.expect_exact(prompt)
100 child.sendline('next')
101 child.expect_exact(prompt)
103 child.sendline('quit')
105 self.child.expect(pexpect.EOF)
109 self.lldb_avg = self.stopwatch.avg()
111 print("lldb disassembly benchmark:", str(self.stopwatch))
114 def run_gdb_disassembly(self, exe, function, count):
116 # Set self.child_prompt, which is "(gdb) ".
117 self.child_prompt = '(gdb) '
118 prompt = self.child_prompt
120 # So that the child gets torn down after the test.
121 self.child = pexpect.spawn('%s --nx %s' % (self.gdbExec, exe))
124 # Turn on logging for what the child sends back.
126 child.logfile_read = sys.stdout
128 child.expect_exact(prompt)
129 child.sendline('break %s' % function)
130 child.expect_exact(prompt)
131 child.sendline('run')
132 child.expect_exact(prompt)
134 # Reset the stopwatch now.
135 self.stopwatch.reset()
136 for i in range(count):
138 # Disassemble the function.
139 child.sendline('disassemble')
140 child.expect_exact(prompt)
141 child.sendline('next')
142 child.expect_exact(prompt)
144 child.sendline('quit')
145 child.expect_exact('The program is running. Exit anyway?')
148 self.child.expect(pexpect.EOF)
152 self.gdb_avg = self.stopwatch.avg()
154 print("gdb disassembly benchmark:", str(self.stopwatch))