Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test that lldb stop-hook works for multiple threads. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 8 | from lldbtest import * |
| 9 | |
| 10 | class StopHookForMultipleThreadsTestCase(TestBase): |
| 11 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 12 | mydir = TestBase.compute_mydir(__file__) |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 13 | |
| 14 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 15 | @dsym_test |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 16 | def test_stop_hook_multiple_threads_with_dsym(self): |
| 17 | """Test that lldb stop-hook works for multiple threads.""" |
| 18 | self.buildDsym(dictionary=self.d) |
| 19 | self.setTearDownCleanup(dictionary=self.d) |
| 20 | self.stop_hook_multiple_threads() |
| 21 | |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 22 | @dwarf_test |
Ed Maste | c82dd2b | 2014-07-31 14:02:32 +0000 | [diff] [blame] | 23 | @expectedFailureFreeBSD("llvm.org/pr15037") |
Todd Fiala | 57cacb01 | 2014-07-10 20:52:08 +0000 | [diff] [blame] | 24 | @expectedFailureLinux("llvm.org/pr15037") # stop hooks sometimes fail to fire on Linux |
Zachary Turner | 0c42631 | 2015-01-20 22:36:03 +0000 | [diff] [blame^] | 25 | @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 26 | def test_stop_hook_multiple_threads_with_dwarf(self): |
| 27 | """Test that lldb stop-hook works for multiple threads.""" |
| 28 | self.buildDwarf(dictionary=self.d) |
| 29 | self.setTearDownCleanup(dictionary=self.d) |
| 30 | self.stop_hook_multiple_threads() |
| 31 | |
| 32 | def setUp(self): |
| 33 | # Call super's setUp(). |
| 34 | TestBase.setUp(self) |
| 35 | # Our simple source filename. |
| 36 | self.source = 'main.cpp' |
| 37 | # Find the line number to break inside main(). |
| 38 | self.first_stop = line_number(self.source, '// Set break point at this line, and add a stop-hook.') |
| 39 | self.thread_function = line_number(self.source, '// Break here to test that the stop-hook mechanism works for multiple threads.') |
| 40 | # Build dictionary to have unique executable names for each test method. |
| 41 | self.exe_name = self.testMethodName |
| 42 | self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} |
| 43 | |
| 44 | def stop_hook_multiple_threads(self): |
| 45 | """Test that lldb stop-hook works for multiple threads.""" |
Zachary Turner | 045fde5 | 2014-07-18 01:02:02 +0000 | [diff] [blame] | 46 | import pexpect |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 47 | exe = os.path.join(os.getcwd(), self.exe_name) |
| 48 | prompt = "(lldb) " |
| 49 | |
| 50 | # So that the child gets torn down after the test. |
Johnny Chen | ebe5172 | 2011-10-07 19:21:09 +0000 | [diff] [blame] | 51 | self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe)) |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 52 | child = self.child |
| 53 | # Turn on logging for what the child sends back. |
| 54 | if self.TraceOn(): |
| 55 | child.logfile_read = sys.stdout |
| 56 | |
| 57 | # Set the breakpoint, followed by the target stop-hook commands. |
| 58 | child.expect_exact(prompt) |
| 59 | child.sendline('breakpoint set -f main.cpp -l %d' % self.first_stop) |
| 60 | child.expect_exact(prompt) |
| 61 | child.sendline('breakpoint set -f main.cpp -l %d' % self.thread_function) |
| 62 | child.expect_exact(prompt) |
| 63 | |
| 64 | # Now run the program, expect to stop at the the first breakpoint which is within the stop-hook range. |
| 65 | child.sendline('run') |
Jason Molenda | ce60807 | 2014-10-02 05:15:07 +0000 | [diff] [blame] | 66 | child.expect_exact("Process") # 'Process 2415 launched', 'Process 2415 stopped' |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 67 | child.expect_exact(prompt) |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 68 | child.sendline('target stop-hook add -o "frame variable --show-globals g_val"') |
Jason Molenda | ce60807 | 2014-10-02 05:15:07 +0000 | [diff] [blame] | 69 | child.expect_exact("Stop hook") # 'Stop hook #1 added.' |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 70 | child.expect_exact(prompt) |
| 71 | |
| 72 | # Continue and expect to find the output emitted by the firing of our stop hook. |
| 73 | child.sendline('continue') |
| 74 | child.expect_exact('(uint32_t) g_val = ') |
| 75 | |
| 76 | |
| 77 | if __name__ == '__main__': |
| 78 | import atexit |
| 79 | lldb.SBDebugger.Initialize() |
| 80 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 81 | unittest2.main() |