]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/stop-hook/multiple_threads/TestStopHookMultipleThreads.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / stop-hook / multiple_threads / TestStopHookMultipleThreads.py
1 """
2 Test that lldb stop-hook works for multiple threads.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import configuration
14 from lldbsuite.test import lldbutil
15
16 class StopHookForMultipleThreadsTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def setUp(self):
21         # Call super's setUp().
22         TestBase.setUp(self)
23         # Our simple source filename.
24         self.source = 'main.cpp'
25         # Find the line number to break inside main().
26         self.first_stop = line_number(self.source, '// Set break point at this line, and add a stop-hook.')
27         self.thread_function = line_number(self.source, '// Break here to test that the stop-hook mechanism works for multiple threads.')
28         # Build dictionary to have unique executable names for each test method.
29         self.exe_name = self.testMethodName
30         self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
31
32     @expectedFlakeyFreeBSD("llvm.org/pr15037")
33     @expectedFlakeyLinux("llvm.org/pr15037") # stop hooks sometimes fail to fire on Linux
34     @expectedFailureAll(hostoslist=["windows"], bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
35     def test_stop_hook_multiple_threads(self):
36         """Test that lldb stop-hook works for multiple threads."""
37         self.build(dictionary=self.d)
38         self.setTearDownCleanup(dictionary=self.d)
39
40         import pexpect
41         exe = os.path.join(os.getcwd(), self.exe_name)
42         prompt = "(lldb) "
43
44         # So that the child gets torn down after the test.
45         self.child = pexpect.spawn('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
46         child = self.child
47         # Turn on logging for what the child sends back.
48         if self.TraceOn():
49             child.logfile_read = sys.stdout
50
51         if lldb.remote_platform:
52             child.expect_exact(prompt)
53             child.sendline('platform select %s' % lldb.remote_platform.GetName())
54             child.expect_exact(prompt)
55             child.sendline('platform connect %s' % configuration.lldb_platform_url)
56             child.expect_exact(prompt)
57             child.sendline('platform settings -w %s' % configuration.lldb_platform_working_dir)
58
59         child.expect_exact(prompt)
60         child.sendline('target create %s' % exe)
61
62         # Set the breakpoint, followed by the target stop-hook commands.
63         child.expect_exact(prompt)
64         child.sendline('breakpoint set -f main.cpp -l %d' % self.first_stop)
65         child.expect_exact(prompt)
66         child.sendline('breakpoint set -f main.cpp -l %d' % self.thread_function)
67         child.expect_exact(prompt)
68
69         # Now run the program, expect to stop at the first breakpoint which is within the stop-hook range.
70         child.sendline('run')
71         child.expect_exact("Process")   # 'Process 2415 launched', 'Process 2415 stopped'
72         child.expect_exact(prompt)
73         child.sendline('target stop-hook add -o "frame variable --show-globals g_val"')
74         child.expect_exact("Stop hook") # 'Stop hook #1 added.'
75         child.expect_exact(prompt)
76
77         # Continue and expect to find the output emitted by the firing of our stop hook.
78         child.sendline('continue')
79         child.expect_exact('(uint32_t) ::g_val = ')