]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/objc/print-obj/TestPrintObj.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / objc / print-obj / TestPrintObj.py
1 """
2 Test "print object" where another thread blocks the print object from making progress.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.lldbtest import *
12
13 @skipUnlessDarwin
14 class PrintObjTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # My source program.
22         self.source = "blocked.m"
23         # Find the line numbers to break at.
24         self.line = line_number(self.source, '// Set a breakpoint here.')
25
26     def test_print_obj(self):
27         """
28         Test "print object" where another thread blocks the print object from making progress.
29
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.
34         """
35         d = {'EXE': 'b.out'}
36         self.build(dictionary=d)
37         self.setTearDownCleanup(dictionary=d)
38         exe = os.path.join(os.getcwd(), 'b.out')
39
40         target = self.dbg.CreateTarget(exe)
41         self.assertTrue(target, VALID_TARGET)
42
43         breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
44         self.assertTrue(breakpoint, VALID_BREAKPOINT)
45         self.runCmd("breakpoint list")
46
47         # Launch the process, and do not stop at the entry point.
48         process = target.LaunchSimple (None, None, self.get_process_working_directory())
49
50         self.runCmd("thread backtrace all")
51
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)
57
58         # Find the other thread.  The iteration protocol of SBProcess and the
59         # rich comparison methods (__eq__/__ne__) of SBThread come in handy.
60         other_thread = None
61         for t in process:
62             if t != this_thread:
63                 other_thread = t
64                 break
65
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)
69         if self.TraceOn():
70             print("selected thread:" + lldbutil.get_description(other_thread))
71         self.runCmd("thread backtrace")
72
73         # We want to traverse the frame to the one corresponding to blocked.m to
74         # issue our 'po lock_me' command.
75
76         depth = other_thread.GetNumFrames()
77         for i in range(depth):
78             frame = other_thread.GetFrameAtIndex(i)
79             name = frame.GetFunctionName()
80             if name == 'main':
81                 other_thread.SetSelectedFrame(i)
82                 if self.TraceOn():
83                     print("selected frame:" + lldbutil.get_description(frame))
84                 break
85
86         self.expect("po lock_me", OBJECT_PRINTED_CORRECTLY,
87             substrs = ['I am pretty special.'])