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