blob: 8aad81c9b4f06d1052f40b9e306ac4aa9dd47d38 [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
8import pexpect
9from lldbtest import *
10
11class StopHookForMultipleThreadsTestCase(TestBase):
12
13 mydir = os.path.join("functionalities", "stop-hook", "multiple_threads")
14
15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16 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
22 def test_stop_hook_multiple_threads_with_dwarf(self):
23 """Test that lldb stop-hook works for multiple threads."""
24 self.buildDwarf(dictionary=self.d)
25 self.setTearDownCleanup(dictionary=self.d)
26 self.stop_hook_multiple_threads()
27
28 def setUp(self):
29 # Call super's setUp().
30 TestBase.setUp(self)
31 # Our simple source filename.
32 self.source = 'main.cpp'
33 # Find the line number to break inside main().
34 self.first_stop = line_number(self.source, '// Set break point at this line, and add a stop-hook.')
35 self.thread_function = line_number(self.source, '// Break here to test that the stop-hook mechanism works for multiple threads.')
36 # Build dictionary to have unique executable names for each test method.
37 self.exe_name = self.testMethodName
38 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
39
40 def stop_hook_multiple_threads(self):
41 """Test that lldb stop-hook works for multiple threads."""
42 exe = os.path.join(os.getcwd(), self.exe_name)
43 prompt = "(lldb) "
44
45 # So that the child gets torn down after the test.
Johnny Chenebe51722011-10-07 19:21:09 +000046 self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe))
Johnny Chen80fdd7c2011-10-05 00:42:59 +000047 child = self.child
48 # Turn on logging for what the child sends back.
49 if self.TraceOn():
50 child.logfile_read = sys.stdout
51
52 # Set the breakpoint, followed by the target stop-hook commands.
53 child.expect_exact(prompt)
54 child.sendline('breakpoint set -f main.cpp -l %d' % self.first_stop)
55 child.expect_exact(prompt)
56 child.sendline('breakpoint set -f main.cpp -l %d' % self.thread_function)
57 child.expect_exact(prompt)
58
59 # Now run the program, expect to stop at the the first breakpoint which is within the stop-hook range.
60 child.sendline('run')
61 child.expect_exact(prompt)
62 child.sendline('target stop-hook add -o "frame variable -g g_val"')
63 child.expect_exact(prompt)
64
65 # Continue and expect to find the output emitted by the firing of our stop hook.
66 child.sendline('continue')
67 child.expect_exact('(uint32_t) g_val = ')
68
69
70if __name__ == '__main__':
71 import atexit
72 lldb.SBDebugger.Initialize()
73 atexit.register(lambda: lldb.SBDebugger.Terminate())
74 unittest2.main()