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 | |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 14 | def setUp(self): |
| 15 | # Call super's setUp(). |
| 16 | TestBase.setUp(self) |
| 17 | # Our simple source filename. |
| 18 | self.source = 'main.cpp' |
| 19 | # Find the line number to break inside main(). |
| 20 | self.first_stop = line_number(self.source, '// Set break point at this line, and add a stop-hook.') |
| 21 | self.thread_function = line_number(self.source, '// Break here to test that the stop-hook mechanism works for multiple threads.') |
| 22 | # Build dictionary to have unique executable names for each test method. |
| 23 | self.exe_name = self.testMethodName |
| 24 | self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} |
| 25 | |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 26 | @expectedFlakeyFreeBSD("llvm.org/pr15037") |
| 27 | @expectedFlakeyLinux("llvm.org/pr15037") # stop hooks sometimes fail to fire on Linux |
| 28 | @expectedFailureHostWindows("llvm.org/pr22274: need a pexpect replacement for windows") |
| 29 | def test_stop_hook_multiple_threads(self): |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 30 | """Test that lldb stop-hook works for multiple threads.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 31 | self.build(dictionary=self.d) |
| 32 | self.setTearDownCleanup(dictionary=self.d) |
| 33 | |
Zachary Turner | 045fde5 | 2014-07-18 01:02:02 +0000 | [diff] [blame] | 34 | import pexpect |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 35 | exe = os.path.join(os.getcwd(), self.exe_name) |
| 36 | prompt = "(lldb) " |
| 37 | |
| 38 | # So that the child gets torn down after the test. |
Tamas Berghammer | 931901e | 2015-07-06 10:46:34 +0000 | [diff] [blame] | 39 | self.child = pexpect.spawn('%s %s' % (lldbtest_config.lldbExec, self.lldbOption)) |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 40 | child = self.child |
| 41 | # Turn on logging for what the child sends back. |
| 42 | if self.TraceOn(): |
| 43 | child.logfile_read = sys.stdout |
| 44 | |
Tamas Berghammer | 931901e | 2015-07-06 10:46:34 +0000 | [diff] [blame] | 45 | if lldb.remote_platform: |
| 46 | child.expect_exact(prompt) |
| 47 | child.sendline('platform select %s' % lldb.remote_platform.GetName()) |
| 48 | child.expect_exact(prompt) |
| 49 | child.sendline('platform connect %s' % lldb.platform_url) |
| 50 | child.expect_exact(prompt) |
| 51 | child.sendline('platform settings -w %s' % lldb.remote_platform_working_dir) |
| 52 | |
| 53 | child.expect_exact(prompt) |
| 54 | child.sendline('target create %s' % exe) |
| 55 | |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 56 | # Set the breakpoint, followed by the target stop-hook commands. |
| 57 | child.expect_exact(prompt) |
| 58 | child.sendline('breakpoint set -f main.cpp -l %d' % self.first_stop) |
| 59 | child.expect_exact(prompt) |
| 60 | child.sendline('breakpoint set -f main.cpp -l %d' % self.thread_function) |
| 61 | child.expect_exact(prompt) |
| 62 | |
Bruce Mitchener | 58ef391 | 2015-06-18 05:27:05 +0000 | [diff] [blame] | 63 | # Now run the program, expect to stop at the first breakpoint which is within the stop-hook range. |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 64 | child.sendline('run') |
Jason Molenda | ce60807 | 2014-10-02 05:15:07 +0000 | [diff] [blame] | 65 | child.expect_exact("Process") # 'Process 2415 launched', 'Process 2415 stopped' |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 66 | child.expect_exact(prompt) |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 67 | 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] | 68 | child.expect_exact("Stop hook") # 'Stop hook #1 added.' |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 69 | child.expect_exact(prompt) |
| 70 | |
| 71 | # Continue and expect to find the output emitted by the firing of our stop hook. |
| 72 | child.sendline('continue') |
Ilia K | b6e094c | 2015-03-26 10:28:15 +0000 | [diff] [blame] | 73 | child.expect_exact('(uint32_t) ::g_val = ') |
Johnny Chen | 80fdd7c | 2011-10-05 00:42:59 +0000 | [diff] [blame] | 74 | |
| 75 | |
| 76 | if __name__ == '__main__': |
| 77 | import atexit |
| 78 | lldb.SBDebugger.Initialize() |
| 79 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 80 | unittest2.main() |