blob: 59c5222f5e19539b3cbd16ee01aea11d885835bf [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
Johnny Chen80fdd7c2011-10-05 00:42:59 +000014 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 Berghammerc8fd1302015-09-30 10:12:40 +000026 @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 Chen80fdd7c2011-10-05 00:42:59 +000030 """Test that lldb stop-hook works for multiple threads."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000031 self.build(dictionary=self.d)
32 self.setTearDownCleanup(dictionary=self.d)
33
Zachary Turner045fde52014-07-18 01:02:02 +000034 import pexpect
Johnny Chen80fdd7c2011-10-05 00:42:59 +000035 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 Berghammer931901e2015-07-06 10:46:34 +000039 self.child = pexpect.spawn('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
Johnny Chen80fdd7c2011-10-05 00:42:59 +000040 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 Berghammer931901e2015-07-06 10:46:34 +000045 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 Chen80fdd7c2011-10-05 00:42:59 +000056 # 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 Mitchener58ef3912015-06-18 05:27:05 +000063 # 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 +000064 child.sendline('run')
Jason Molendace608072014-10-02 05:15:07 +000065 child.expect_exact("Process") # 'Process 2415 launched', 'Process 2415 stopped'
Johnny Chen80fdd7c2011-10-05 00:42:59 +000066 child.expect_exact(prompt)
Greg Clayton3bcdfc02012-12-04 00:32:51 +000067 child.sendline('target stop-hook add -o "frame variable --show-globals g_val"')
Jason Molendace608072014-10-02 05:15:07 +000068 child.expect_exact("Stop hook") # 'Stop hook #1 added.'
Johnny Chen80fdd7c2011-10-05 00:42:59 +000069 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 Kb6e094c2015-03-26 10:28:15 +000073 child.expect_exact('(uint32_t) ::g_val = ')
Johnny Chen80fdd7c2011-10-05 00:42:59 +000074
75
76if __name__ == '__main__':
77 import atexit
78 lldb.SBDebugger.Initialize()
79 atexit.register(lambda: lldb.SBDebugger.Terminate())
80 unittest2.main()