2 Test "print object" where another thread blocks the print object from making progress.
6 from lldbsuite
.test
.decorators
import *
7 from lldbsuite
.test
.lldbtest
import *
8 from lldbsuite
.test
import lldbutil
11 class PrintObjTestCase(TestBase
):
13 # Call super's setUp().
16 self
.source
= "blocked.m"
17 # Find the line numbers to break at.
18 self
.line
= line_number(self
.source
, "// Set a breakpoint here.")
20 def test_print_obj(self
):
22 Test "print object" where another thread blocks the print object from making progress.
24 Set a breakpoint on the line in my_pthread_routine. Then switch threads
25 to the main thread, and do print the lock_me object. Since that will
26 try to get the lock already gotten by my_pthread_routime thread, it will
27 have to switch to running all threads, and that should then succeed.
30 self
.build(dictionary
=d
)
31 self
.setTearDownCleanup(dictionary
=d
)
32 exe
= self
.getBuildArtifact("b.out")
34 target
= self
.dbg
.CreateTarget(exe
)
35 self
.assertTrue(target
, VALID_TARGET
)
37 breakpoint
= target
.BreakpointCreateByLocation(self
.source
, self
.line
)
38 self
.assertTrue(breakpoint
, VALID_BREAKPOINT
)
39 self
.runCmd("breakpoint list")
41 # Launch the process, and do not stop at the entry point.
42 process
= target
.LaunchSimple(None, None, self
.get_process_working_directory())
44 self
.runCmd("thread backtrace all")
46 # Let's get the current stopped thread. We'd like to switch to the
47 # other thread to issue our 'po lock_me' command.
48 import lldbsuite
.test
.lldbutil
as lldbutil
50 this_thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonBreakpoint
)
51 self
.assertTrue(this_thread
)
53 # Find the other thread. The iteration protocol of SBProcess and the
54 # rich comparison methods (__eq__/__ne__) of SBThread come in handy.
61 # Set the other thread as the selected thread to issue our 'po'
63 self
.assertTrue(other_thread
)
64 process
.SetSelectedThread(other_thread
)
66 print("selected thread:" + lldbutil
.get_description(other_thread
))
67 self
.runCmd("thread backtrace")
69 # We want to traverse the frame to the one corresponding to blocked.m to
70 # issue our 'po lock_me' command.
72 depth
= other_thread
.GetNumFrames()
73 for i
in range(depth
):
74 frame
= other_thread
.GetFrameAtIndex(i
)
75 name
= frame
.GetFunctionName()
77 other_thread
.SetSelectedFrame(i
)
79 print("selected frame:" + lldbutil
.get_description(frame
))
83 "po lock_me", OBJECT_PRINTED_CORRECTLY
, substrs
=["I am pretty special."]