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 |
| 8 | import pexpect |
| 9 | from lldbtest import * |
| 10 | |
| 11 | class StopHookForMultipleThreadsTestCase(TestBase): |
| 12 | |
| 13 | mydir = os.path.join("functionalities", "stop-hook", "multiple_threads") |
| 14 | |
| 15 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame^] | 16 | @dsym_test |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 17 | def test_stop_hook_multiple_threads_with_dsym(self): |
| 18 | """Test that lldb stop-hook works for multiple threads.""" |
| 19 | self.buildDsym(dictionary=self.d) |
| 20 | self.setTearDownCleanup(dictionary=self.d) |
| 21 | self.stop_hook_multiple_threads() |
| 22 | |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame^] | 23 | @dwarf_test |
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.""" |
| 44 | exe = os.path.join(os.getcwd(), self.exe_name) |
| 45 | prompt = "(lldb) " |
| 46 | |
| 47 | # So that the child gets torn down after the test. |
Johnny Chen | ebe5172 | 2011-10-07 19:21:09 +0000 | [diff] [blame] | 48 | self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe)) |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 49 | child = self.child |
| 50 | # Turn on logging for what the child sends back. |
| 51 | if self.TraceOn(): |
| 52 | child.logfile_read = sys.stdout |
| 53 | |
| 54 | # Set the breakpoint, followed by the target stop-hook commands. |
| 55 | child.expect_exact(prompt) |
| 56 | child.sendline('breakpoint set -f main.cpp -l %d' % self.first_stop) |
| 57 | child.expect_exact(prompt) |
| 58 | child.sendline('breakpoint set -f main.cpp -l %d' % self.thread_function) |
| 59 | child.expect_exact(prompt) |
| 60 | |
| 61 | # Now run the program, expect to stop at the the first breakpoint which is within the stop-hook range. |
| 62 | child.sendline('run') |
| 63 | child.expect_exact(prompt) |
| 64 | child.sendline('target stop-hook add -o "frame variable -g g_val"') |
| 65 | child.expect_exact(prompt) |
| 66 | |
| 67 | # Continue and expect to find the output emitted by the firing of our stop hook. |
| 68 | child.sendline('continue') |
| 69 | child.expect_exact('(uint32_t) g_val = ') |
| 70 | |
| 71 | |
| 72 | if __name__ == '__main__': |
| 73 | import atexit |
| 74 | lldb.SBDebugger.Initialize() |
| 75 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 76 | unittest2.main() |