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 |
Todd Fiala | 57cacb01 | 2014-07-10 20:52:08 +0000 | [diff] [blame] | 23 | @expectedFailureLinux("llvm.org/pr15037") # stop hooks sometimes fail to fire on Linux |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 24 | def test_stop_hook_multiple_threads_with_dwarf(self): |
| 25 | """Test that lldb stop-hook works for multiple threads.""" |
| 26 | self.buildDwarf(dictionary=self.d) |
| 27 | self.setTearDownCleanup(dictionary=self.d) |
| 28 | self.stop_hook_multiple_threads() |
| 29 | |
| 30 | def setUp(self): |
| 31 | # Call super's setUp(). |
| 32 | TestBase.setUp(self) |
| 33 | # Our simple source filename. |
| 34 | self.source = 'main.cpp' |
| 35 | # Find the line number to break inside main(). |
| 36 | self.first_stop = line_number(self.source, '// Set break point at this line, and add a stop-hook.') |
| 37 | self.thread_function = line_number(self.source, '// Break here to test that the stop-hook mechanism works for multiple threads.') |
| 38 | # Build dictionary to have unique executable names for each test method. |
| 39 | self.exe_name = self.testMethodName |
| 40 | self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} |
| 41 | |
| 42 | def stop_hook_multiple_threads(self): |
| 43 | """Test that lldb stop-hook works for multiple threads.""" |
Zachary Turner | 045fde5 | 2014-07-18 01:02:02 +0000 | [diff] [blame^] | 44 | import pexpect |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 45 | exe = os.path.join(os.getcwd(), self.exe_name) |
| 46 | prompt = "(lldb) " |
| 47 | |
| 48 | # So that the child gets torn down after the test. |
Johnny Chen | ebe5172 | 2011-10-07 19:21:09 +0000 | [diff] [blame] | 49 | self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe)) |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 50 | child = self.child |
| 51 | # Turn on logging for what the child sends back. |
| 52 | if self.TraceOn(): |
| 53 | child.logfile_read = sys.stdout |
| 54 | |
| 55 | # Set the breakpoint, followed by the target stop-hook commands. |
| 56 | child.expect_exact(prompt) |
| 57 | child.sendline('breakpoint set -f main.cpp -l %d' % self.first_stop) |
| 58 | child.expect_exact(prompt) |
| 59 | child.sendline('breakpoint set -f main.cpp -l %d' % self.thread_function) |
| 60 | child.expect_exact(prompt) |
| 61 | |
| 62 | # Now run the program, expect to stop at the the first breakpoint which is within the stop-hook range. |
| 63 | child.sendline('run') |
| 64 | child.expect_exact(prompt) |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 65 | child.sendline('target stop-hook add -o "frame variable --show-globals g_val"') |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 66 | child.expect_exact(prompt) |
| 67 | |
| 68 | # Continue and expect to find the output emitted by the firing of our stop hook. |
| 69 | child.sendline('continue') |
| 70 | child.expect_exact('(uint32_t) g_val = ') |
| 71 | |
| 72 | |
| 73 | if __name__ == '__main__': |
| 74 | import atexit |
| 75 | lldb.SBDebugger.Initialize() |
| 76 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 77 | unittest2.main() |