blob: d5534750e2b553420d9e042e4e6da658babee704 [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
Ed Mastec82dd2b2014-07-31 14:02:32 +000023 @expectedFailureFreeBSD("llvm.org/pr15037")
Todd Fiala57cacb012014-07-10 20:52:08 +000024 @expectedFailureLinux("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")
Johnny Chen80fdd7c2011-10-05 00:42:59 +000026 def test_stop_hook_multiple_threads_with_dwarf(self):
27 """Test that lldb stop-hook works for multiple threads."""
28 self.buildDwarf(dictionary=self.d)
29 self.setTearDownCleanup(dictionary=self.d)
30 self.stop_hook_multiple_threads()
31
32 def setUp(self):
33 # Call super's setUp().
34 TestBase.setUp(self)
35 # Our simple source filename.
36 self.source = 'main.cpp'
37 # Find the line number to break inside main().
38 self.first_stop = line_number(self.source, '// Set break point at this line, and add a stop-hook.')
39 self.thread_function = line_number(self.source, '// Break here to test that the stop-hook mechanism works for multiple threads.')
40 # Build dictionary to have unique executable names for each test method.
41 self.exe_name = self.testMethodName
42 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
43
44 def stop_hook_multiple_threads(self):
45 """Test that lldb stop-hook works for multiple threads."""
Zachary Turner045fde52014-07-18 01:02:02 +000046 import pexpect
Johnny Chen80fdd7c2011-10-05 00:42:59 +000047 exe = os.path.join(os.getcwd(), self.exe_name)
48 prompt = "(lldb) "
49
50 # So that the child gets torn down after the test.
Johnny Chenebe51722011-10-07 19:21:09 +000051 self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe))
Johnny Chen80fdd7c2011-10-05 00:42:59 +000052 child = self.child
53 # Turn on logging for what the child sends back.
54 if self.TraceOn():
55 child.logfile_read = sys.stdout
56
57 # Set the breakpoint, followed by the target stop-hook commands.
58 child.expect_exact(prompt)
59 child.sendline('breakpoint set -f main.cpp -l %d' % self.first_stop)
60 child.expect_exact(prompt)
61 child.sendline('breakpoint set -f main.cpp -l %d' % self.thread_function)
62 child.expect_exact(prompt)
63
64 # Now run the program, expect to stop at the the first breakpoint which is within the stop-hook range.
65 child.sendline('run')
Jason Molendace608072014-10-02 05:15:07 +000066 child.expect_exact("Process") # 'Process 2415 launched', 'Process 2415 stopped'
Johnny Chen80fdd7c2011-10-05 00:42:59 +000067 child.expect_exact(prompt)
Greg Clayton3bcdfc02012-12-04 00:32:51 +000068 child.sendline('target stop-hook add -o "frame variable --show-globals g_val"')
Jason Molendace608072014-10-02 05:15:07 +000069 child.expect_exact("Stop hook") # 'Stop hook #1 added.'
Johnny Chen80fdd7c2011-10-05 00:42:59 +000070 child.expect_exact(prompt)
71
72 # Continue and expect to find the output emitted by the firing of our stop hook.
73 child.sendline('continue')
74 child.expect_exact('(uint32_t) g_val = ')
75
76
77if __name__ == '__main__':
78 import atexit
79 lldb.SBDebugger.Initialize()
80 atexit.register(lambda: lldb.SBDebugger.Terminate())
81 unittest2.main()