blob: 9e7d7ffae9067e59e078d4d44ad733cc0d8e37d5 [file] [log] [blame]
Johnny Chen80fdd7c2011-10-05 00:42:59 +00001"""
2Test that lldb stop-hook works for multiple threads.
3"""
4
5import os, time
6import unittest2
7import lldb
Johnny Chen80fdd7c2011-10-05 00:42:59 +00008from lldbtest import *
9
10class StopHookForMultipleThreadsTestCase(TestBase):
11
Greg Clayton4570d3e2013-12-10 23:19:29 +000012 mydir = TestBase.compute_mydir(__file__)
Johnny Chen80fdd7c2011-10-05 00:42:59 +000013
Robert Flack13c7ad92015-03-30 14:12:17 +000014 @skipUnlessDarwin
Johnny Chenf1548d42012-04-06 00:56:05 +000015 @dsym_test
Johnny Chen80fdd7c2011-10-05 00:42:59 +000016 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 Chenf1548d42012-04-06 00:56:05 +000022 @dwarf_test
Ed Mastec82dd2b2014-07-31 14:02:32 +000023 @expectedFailureFreeBSD("llvm.org/pr15037")
Vince Harron7ac3ea42015-06-26 15:13:21 +000024 @expectedFlakeyLinux("llvm.org/pr15037") # stop hooks sometimes fail to fire on Linux
Zachary Turner0c426312015-01-20 22:36:03 +000025 @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
Ed Maste8eeb3e22015-06-03 21:21:40 +000026 @skipIfFreeBSD # llvm.org/pr22784
Johnny Chen80fdd7c2011-10-05 00:42:59 +000027 def test_stop_hook_multiple_threads_with_dwarf(self):
28 """Test that lldb stop-hook works for multiple threads."""
29 self.buildDwarf(dictionary=self.d)
30 self.setTearDownCleanup(dictionary=self.d)
31 self.stop_hook_multiple_threads()
32
33 def setUp(self):
34 # Call super's setUp().
35 TestBase.setUp(self)
36 # Our simple source filename.
37 self.source = 'main.cpp'
38 # Find the line number to break inside main().
39 self.first_stop = line_number(self.source, '// Set break point at this line, and add a stop-hook.')
40 self.thread_function = line_number(self.source, '// Break here to test that the stop-hook mechanism works for multiple threads.')
41 # Build dictionary to have unique executable names for each test method.
42 self.exe_name = self.testMethodName
43 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
44
45 def stop_hook_multiple_threads(self):
46 """Test that lldb stop-hook works for multiple threads."""
Zachary Turner045fde52014-07-18 01:02:02 +000047 import pexpect
Johnny Chen80fdd7c2011-10-05 00:42:59 +000048 exe = os.path.join(os.getcwd(), self.exe_name)
49 prompt = "(lldb) "
50
51 # So that the child gets torn down after the test.
Vince Harron790d95c2015-05-18 19:39:03 +000052 self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
Johnny Chen80fdd7c2011-10-05 00:42:59 +000053 child = self.child
54 # Turn on logging for what the child sends back.
55 if self.TraceOn():
56 child.logfile_read = sys.stdout
57
58 # Set the breakpoint, followed by the target stop-hook commands.
59 child.expect_exact(prompt)
60 child.sendline('breakpoint set -f main.cpp -l %d' % self.first_stop)
61 child.expect_exact(prompt)
62 child.sendline('breakpoint set -f main.cpp -l %d' % self.thread_function)
63 child.expect_exact(prompt)
64
Bruce Mitchener58ef3912015-06-18 05:27:05 +000065 # Now run the program, expect to stop at the first breakpoint which is within the stop-hook range.
Johnny Chen80fdd7c2011-10-05 00:42:59 +000066 child.sendline('run')
Jason Molendace608072014-10-02 05:15:07 +000067 child.expect_exact("Process") # 'Process 2415 launched', 'Process 2415 stopped'
Johnny Chen80fdd7c2011-10-05 00:42:59 +000068 child.expect_exact(prompt)
Greg Clayton3bcdfc02012-12-04 00:32:51 +000069 child.sendline('target stop-hook add -o "frame variable --show-globals g_val"')
Jason Molendace608072014-10-02 05:15:07 +000070 child.expect_exact("Stop hook") # 'Stop hook #1 added.'
Johnny Chen80fdd7c2011-10-05 00:42:59 +000071 child.expect_exact(prompt)
72
73 # Continue and expect to find the output emitted by the firing of our stop hook.
74 child.sendline('continue')
Ilia Kb6e094c2015-03-26 10:28:15 +000075 child.expect_exact('(uint32_t) ::g_val = ')
Johnny Chen80fdd7c2011-10-05 00:42:59 +000076
77
78if __name__ == '__main__':
79 import atexit
80 lldb.SBDebugger.Initialize()
81 atexit.register(lambda: lldb.SBDebugger.Terminate())
82 unittest2.main()