blob: 0627b0202296753d86efd8d5d57311b91e29abee [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
14 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
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
Todd Fiala57cacb012014-07-10 20:52:08 +000023 @expectedFailureLinux("llvm.org/pr15037") # stop hooks sometimes fail to fire on Linux
Johnny Chen80fdd7c2011-10-05 00:42:59 +000024 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 Turner045fde52014-07-18 01:02:02 +000044 import pexpect
Johnny Chen80fdd7c2011-10-05 00:42:59 +000045 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 Chenebe51722011-10-07 19:21:09 +000049 self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe))
Johnny Chen80fdd7c2011-10-05 00:42:59 +000050 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 Clayton3bcdfc02012-12-04 00:32:51 +000065 child.sendline('target stop-hook add -o "frame variable --show-globals g_val"')
Johnny Chen80fdd7c2011-10-05 00:42:59 +000066 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
73if __name__ == '__main__':
74 import atexit
75 lldb.SBDebugger.Initialize()
76 atexit.register(lambda: lldb.SBDebugger.Terminate())
77 unittest2.main()