2 Test that lldb stop-hook works for multiple threads.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import configuration
14 from lldbsuite.test import lldbutil
16 class StopHookForMultipleThreadsTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
21 # Call super's setUp().
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}
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)
41 exe = os.path.join(os.getcwd(), self.exe_name)
44 # So that the child gets torn down after the test.
45 self.child = pexpect.spawn('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
47 # Turn on logging for what the child sends back.
49 child.logfile_read = sys.stdout
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)
59 child.expect_exact(prompt)
60 child.sendline('target create %s' % exe)
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)
69 # Now run the program, expect to stop at the first breakpoint which is within the stop-hook range.
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)
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 = ')