]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / thread / thread_specific_break / TestThreadSpecificBreakpoint.py
1 """
2 Test that we obey thread conditioned breakpoints.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import re
11 import lldb
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
15
16 class ThreadSpecificBreakTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     @add_test_categories(['pyapi'])
21     @expectedFailureAll(oslist=["windows"])
22     def test_python(self):
23         """Test that we obey thread conditioned breakpoints."""
24         self.build()
25         exe = os.path.join(os.getcwd(), "a.out")
26
27         target = self.dbg.CreateTarget(exe)
28         self.assertTrue(target, VALID_TARGET)
29
30         # This test works by setting a breakpoint in a function conditioned to stop only on
31         # the main thread, and then calling this function on a secondary thread, joining,
32         # and then calling again on the main thread.  If the thread specific breakpoint works
33         # then it should not be hit on the secondary thread, only on the main thread.
34
35         main_source_spec = lldb.SBFileSpec ("main.cpp")
36
37         main_breakpoint = target.BreakpointCreateBySourceRegex("Set main breakpoint here", main_source_spec);
38         thread_breakpoint = target.BreakpointCreateBySourceRegex("Set thread-specific breakpoint here", main_source_spec)
39
40         self.assertTrue(main_breakpoint.IsValid(), "Failed to set main breakpoint.")
41         self.assertGreater(main_breakpoint.GetNumLocations(), 0, "main breakpoint has no locations associated with it.")
42         self.assertTrue(thread_breakpoint.IsValid(), "Failed to set thread breakpoint.")
43         self.assertGreater(thread_breakpoint.GetNumLocations(), 0, "thread breakpoint has no locations associated with it.")
44
45         process = target.LaunchSimple (None, None, self.get_process_working_directory())
46
47         self.assertTrue(process, PROCESS_IS_VALID)
48
49         stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(process, main_breakpoint)
50         self.assertEqual(len(stopped_threads), 1, "main breakpoint stopped at unexpected number of threads")
51         main_thread = stopped_threads[0]
52         main_thread_id = main_thread.GetThreadID()
53
54         # Set the thread-specific breakpoint to only stop on the main thread.  The run the function
55         # on another thread and join on it.  If the thread-specific breakpoint works, the next
56         # stop should be on the main thread.
57         thread_breakpoint.SetThreadID(main_thread_id)
58
59         process.Continue()
60         next_stop_state = process.GetState()
61         self.assertEqual(next_stop_state, lldb.eStateStopped, "We should have stopped at the thread breakpoint.")
62         stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(process, thread_breakpoint)
63         self.assertEqual(len(stopped_threads), 1, "thread breakpoint stopped at unexpected number of threads")
64         self.assertEqual(stopped_threads[0].GetThreadID(), main_thread_id, "thread breakpoint stopped at the wrong thread")