aboutsummaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break_plus_condition/TestThreadSpecificBpPlusCondition.py
blob: b4a0b7a5dd4eedcc2d0f641defdcb59aee81e626 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Test that we obey thread conditioned breakpoints and expression
conditioned breakpoints simultaneously
"""

from __future__ import print_function



import os, time
import re
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *

class ThreadSpecificBreakPlusConditionTestCase(TestBase):

    mydir = TestBase.compute_mydir(__file__)

    @skipIfFreeBSD # test frequently times out or hangs
    @expectedFailureFreeBSD('llvm.org/pr18522') # hits break in another thread in testrun
    @add_test_categories(['pyapi'])
    @expectedFailureWindows # Thread specific breakpoints cause the inferior to crash.
    @expectedFlakeyLinux # this test fails 6/100 dosep runs
    def test_python(self):
        """Test that we obey thread conditioned breakpoints."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        main_source_spec = lldb.SBFileSpec ("main.cpp")

        # Set a breakpoint in the thread body, and make it active for only the first thread.
        break_thread_body = target.BreakpointCreateBySourceRegex ("Break here in thread body.", main_source_spec)
        self.assertTrue (break_thread_body.IsValid() and break_thread_body.GetNumLocations() > 0, "Failed to set thread body breakpoint.")

        process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_thread_body)
        
        victim_thread = threads[0]

        # Pick one of the threads, and change the breakpoint so it ONLY stops for this thread,
        # but add a condition that it won't stop for this thread's my_value.  The other threads
        # pass the condition, so they should stop, but if the thread-specification is working
        # they should not stop.  So nobody should hit the breakpoint anymore, and we should
        # just exit cleanly.

        frame = victim_thread.GetFrameAtIndex(0)
        value = frame.FindVariable("my_value").GetValueAsSigned(0)
        self.assertTrue (value > 0 and value < 11, "Got a reasonable value for my_value.")

        cond_string = "my_value != %d"%(value)

        break_thread_body.SetThreadID(victim_thread.GetThreadID())
        break_thread_body.SetCondition (cond_string)

        process.Continue()

        next_stop_state = process.GetState()
        self.assertTrue (next_stop_state == lldb.eStateExited, "We should have not hit the breakpoint again.")