2 Test "print object" where another thread blocks the print object from making progress.
5 from __future__ import print_function
11 from lldbsuite.test.lldbtest import *
14 class PrintObjTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
19 # Call super's setUp().
22 self.source = "blocked.m"
23 # Find the line numbers to break at.
24 self.line = line_number(self.source, '// Set a breakpoint here.')
26 def test_print_obj(self):
28 Test "print object" where another thread blocks the print object from making progress.
30 Set a breakpoint on the line in my_pthread_routine. Then switch threads
31 to the main thread, and do print the lock_me object. Since that will
32 try to get the lock already gotten by my_pthread_routime thread, it will
33 have to switch to running all threads, and that should then succeed.
36 self.build(dictionary=d)
37 self.setTearDownCleanup(dictionary=d)
38 exe = os.path.join(os.getcwd(), 'b.out')
40 target = self.dbg.CreateTarget(exe)
41 self.assertTrue(target, VALID_TARGET)
43 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
44 self.assertTrue(breakpoint, VALID_BREAKPOINT)
45 self.runCmd("breakpoint list")
47 # Launch the process, and do not stop at the entry point.
48 process = target.LaunchSimple (None, None, self.get_process_working_directory())
50 self.runCmd("thread backtrace all")
52 # Let's get the current stopped thread. We'd like to switch to the
53 # other thread to issue our 'po lock_me' command.
54 import lldbsuite.test.lldbutil as lldbutil
55 this_thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
56 self.assertTrue(this_thread)
58 # Find the other thread. The iteration protocol of SBProcess and the
59 # rich comparison methods (__eq__/__ne__) of SBThread come in handy.
66 # Set the other thread as the selected thread to issue our 'po' command.other
67 self.assertTrue(other_thread)
68 process.SetSelectedThread(other_thread)
70 print("selected thread:" + lldbutil.get_description(other_thread))
71 self.runCmd("thread backtrace")
73 # We want to traverse the frame to the one corresponding to blocked.m to
74 # issue our 'po lock_me' command.
76 depth = other_thread.GetNumFrames()
77 for i in range(depth):
78 frame = other_thread.GetFrameAtIndex(i)
79 name = frame.GetFunctionName()
81 other_thread.SetSelectedFrame(i)
83 print("selected frame:" + lldbutil.get_description(frame))
86 self.expect("po lock_me", OBJECT_PRINTED_CORRECTLY,
87 substrs = ['I am pretty special.'])