Sat, 31 Dec 2016 13:34:21 +0100
Updated copyright for 2017.
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
2 | |
5389
9b1c800daff3
Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5273
diff
changeset
|
3 | # Copyright (c) 2014 - 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
4 | # |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
5 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
6 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
7 | Module implementing an import hook patching thread modules to get debugged too. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
8 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
9 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
10 | import os.path |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
11 | import sys |
5240
71c51aae2f4e
Use importlib instead __import__ because it returns the correct module directly.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5228
diff
changeset
|
12 | import importlib |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
13 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
14 | if sys.version_info[0] == 2: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
15 | import thread as _thread |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
16 | else: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
17 | import _thread |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
18 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
19 | import threading |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
20 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
21 | from DebugBase import DebugBase |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
22 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
23 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
24 | class ThreadExtension(object): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
25 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
26 | Class implementing the thread support for the debugger. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
27 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
28 | Provides methods for intercepting thread creation, retriving the running |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
29 | threads and their name and state. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
30 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
31 | def __init__(self): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
32 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
33 | Constructor |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
34 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
35 | self.threadNumber = 1 |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
36 | self.enableImportHooks = True |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
37 | self._original_start_new_thread = None |
5228
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
38 | self._qtThread = None |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
39 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
40 | self.clientLock = threading.RLock() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
41 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
42 | # dictionary of all threads running {id: DebugBase} |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
43 | self.threads = {_thread.get_ident(): self} |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
44 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
45 | # the "current" thread, basically for variables view |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
46 | self.currentThread = self |
5221
960afd19c1b6
Give the next debugger command to the thread where we are stopped at the moment.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5209
diff
changeset
|
47 | # the thread we are at a breakpoint continuing at next command |
960afd19c1b6
Give the next debugger command to the thread where we are stopped at the moment.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5209
diff
changeset
|
48 | self.currentThreadExec = self |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
49 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
50 | # special objects representing the main scripts thread and frame |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
51 | self.mainThread = self |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
52 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
53 | if sys.version_info[0] == 2: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
54 | self.threadModName = 'thread' |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
55 | else: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
56 | self.threadModName = '_thread' |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
57 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
58 | # reset already imported thread module to apply hooks at next import |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
59 | del sys.modules[self.threadModName] |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
60 | del sys.modules['threading'] |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
61 | |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
62 | sys.meta_path.insert(0, self) |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
63 | |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
64 | def attachThread(self, target=None, args=None, kwargs={}, |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
65 | mainThread=False): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
66 | """ |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
67 | Public method to setup a standard thread for DebugClient to debug. |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
68 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
69 | If mainThread is True, then we are attaching to the already |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
70 | started mainthread of the app and the rest of the args are ignored. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
71 | |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
72 | @param target the start function of the target thread (i.e. the user |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
73 | code) |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
74 | @param args arguments to pass to target |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
75 | @param kwargs keyword arguments to pass to target |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
76 | @param mainThread True, if we are attaching to the already |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
77 | started mainthread of the app |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
78 | @return identifier of the created thread |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
79 | """ |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
80 | if mainThread: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
81 | ident = _thread.get_ident() |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
82 | name = 'MainThread' |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
83 | newThread = self.mainThread |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
84 | newThread.isMainThread = True |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
85 | if self.debugging: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
86 | sys.setprofile(newThread.profile) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
87 | |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
88 | else: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
89 | newThread = DebugBase(self) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
90 | ident = self._original_start_new_thread( |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
91 | newThread.bootstrap, (target, args, kwargs)) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
92 | name = 'Thread-{0}'.format(self.threadNumber) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
93 | self.threadNumber += 1 |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
94 | |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
95 | newThread.id = ident |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
96 | newThread.name = name |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
97 | |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
98 | self.threads[ident] = newThread |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
99 | |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
100 | return ident |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
101 | |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
102 | def threadTerminated(self, threadId): |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
103 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
104 | Public method called when a DebugThread has exited. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
105 | |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
106 | @param threadId id of the DebugThread that has exited |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
107 | @type int |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
108 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
109 | self.lockClient() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
110 | try: |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
111 | del self.threads[threadId] |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
112 | except KeyError: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
113 | pass |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
114 | finally: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
115 | self.unlockClient() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
116 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
117 | def lockClient(self, blocking=True): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
118 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
119 | Public method to acquire the lock for this client. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
120 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
121 | @param blocking flag to indicating a blocking lock |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
122 | @type bool |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
123 | @return flag indicating successful locking |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
124 | @rtype bool |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
125 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
126 | if blocking: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
127 | self.clientLock.acquire() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
128 | else: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
129 | return self.clientLock.acquire(blocking) |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
130 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
131 | def unlockClient(self): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
132 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
133 | Public method to release the lock for this client. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
134 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
135 | try: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
136 | self.clientLock.release() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
137 | except AssertionError: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
138 | pass |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
139 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
140 | def setCurrentThread(self, id): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
141 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
142 | Public method to set the current thread. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
143 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
144 | @param id the id the current thread should be set to. |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
145 | @type int |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
146 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
147 | try: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
148 | self.lockClient() |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
149 | if id is None: |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
150 | self.currentThread = None |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
151 | else: |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
152 | self.currentThread = self.threads.get(id) |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
153 | finally: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
154 | self.unlockClient() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
155 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
156 | def dumpThreadList(self): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
157 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
158 | Public method to send the list of threads. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
159 | """ |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
160 | self.updateThreadList() |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
161 | threadList = [] |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
162 | if len(self.threads) > 1: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
163 | currentId = _thread.get_ident() |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
164 | # update thread names set by user (threading.setName) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
165 | threadNames = {t.ident: t.getName() for t in threading.enumerate()} |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
166 | |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
167 | for id, thd in self.threads.items(): |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
168 | d = {"id": id} |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
169 | try: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
170 | d["name"] = threadNames.get(id, thd.name) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
171 | d["broken"] = thd.isBroken |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
172 | except Exception: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
173 | d["name"] = 'UnknownThread' |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
174 | d["broken"] = False |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
175 | |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
176 | threadList.append(d) |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
177 | else: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
178 | currentId = -1 |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
179 | d = {"id": -1} |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
180 | d["name"] = "MainThread" |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
181 | d["broken"] = self.isBroken |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
182 | threadList.append(d) |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
183 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
184 | self.sendJsonCommand("ResponseThreadList", { |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
185 | "currentID": currentId, |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
186 | "threadList": threadList, |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
187 | }) |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
188 | |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
189 | def getExecutedFrame(self, frame): |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
190 | """ |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
191 | Public method to return the currently executed frame. |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
192 | |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
193 | @param frame the current frame |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
194 | @type frame object |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
195 | @return the frame which is excecuted (without debugger frames) |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
196 | @rtype frame object |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
197 | """ |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
198 | # to get the currently executed frame, skip all frames belonging to the |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
199 | # debugger |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
200 | while frame is not None: |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
201 | baseName = os.path.basename(frame.f_code.co_filename) |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
202 | if not baseName.startswith( |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
203 | ('DebugClientBase.py', 'DebugBase.py', 'AsyncIO.py', |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
204 | 'ThreadExtension.py', 'threading.py')): |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
205 | break |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
206 | frame = frame.f_back |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
207 | |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
208 | return frame |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
209 | |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
210 | def updateThreadList(self): |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
211 | """ |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
212 | Public method to update the list of running threads. |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
213 | """ |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
214 | frames = sys._current_frames() |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
215 | for id, frame in frames.items(): |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
216 | # skip our own timer thread |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
217 | if frame.f_code.co_name == '__eventPollTimer': |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
218 | continue |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
219 | |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
220 | # Unknown thread |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
221 | if id not in self.threads: |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
222 | newThread = DebugBase(self) |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
223 | name = 'Thread-{0}'.format(self.threadNumber) |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
224 | self.threadNumber += 1 |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
225 | |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
226 | newThread.id = id |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
227 | newThread.name = name |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
228 | self.threads[id] = newThread |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
229 | |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
230 | # adjust current frame |
5269
0e96e1557c45
Fix for PyPy showing no local variables and suppress exception on old frames.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5240
diff
changeset
|
231 | if "__pypy__" not in sys.builtin_module_names: |
0e96e1557c45
Fix for PyPy showing no local variables and suppress exception on old frames.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5240
diff
changeset
|
232 | self.threads[id].currentFrame = self.getExecutedFrame(frame) |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
233 | |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
234 | # Clean up obsolet because terminated threads |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
235 | self.threads = {id_: thrd for id_, thrd in self.threads.items() |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
236 | if id_ in frames} |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
237 | |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
238 | def find_module(self, fullname, path=None): |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
239 | """ |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
240 | Public method returning the module loader. |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
241 | |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
242 | @param fullname name of the module to be loaded |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
243 | @type str |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
244 | @param path path to resolve the module name |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
245 | @type str |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
246 | @return module loader object |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
247 | @rtype object |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
248 | """ |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
249 | if fullname in sys.modules or not self.debugging: |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
250 | return None |
5228
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
251 | |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
252 | if fullname in [self.threadModName, 'PyQt4.QtCore', 'PyQt5.QtCore', |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
253 | 'PySide.QtCore'] and self.enableImportHooks: |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
254 | # Disable hook to be able to import original module |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
255 | self.enableImportHooks = False |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
256 | return self |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
257 | |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
258 | return None |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
259 | |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
260 | def load_module(self, fullname): |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
261 | """ |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
262 | Public method to load a module. |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
263 | |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
264 | @param fullname name of the module to be loaded |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
265 | @type str |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
266 | @return reference to the loaded module |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
267 | @rtype module |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
268 | """ |
5240
71c51aae2f4e
Use importlib instead __import__ because it returns the correct module directly.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5228
diff
changeset
|
269 | module = importlib.import_module(fullname) |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
270 | sys.modules[fullname] = module |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
271 | if (fullname == self.threadModName and |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
272 | self._original_start_new_thread is None): |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
273 | # make thread hooks available to system |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
274 | self._original_start_new_thread = module.start_new_thread |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
275 | module.start_new_thread = self.attachThread |
5228
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
276 | elif fullname in ['PyQt4.QtCore', 'PyQt5.QtCore', |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
277 | 'PySide.QtCore'] and self._qtThread is None: |
5240
71c51aae2f4e
Use importlib instead __import__ because it returns the correct module directly.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5228
diff
changeset
|
278 | self._qtThread = module.QThread |
5228
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
279 | # _debugClient as a class attribute can't be accessed in following |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
280 | # class. Therefore we need a global variable. |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
281 | _debugClient = self |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
282 | |
5240
71c51aae2f4e
Use importlib instead __import__ because it returns the correct module directly.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5228
diff
changeset
|
283 | class QThreadWrapper(module.QThread): |
5228
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
284 | __qtThreadNumber = 1 |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
285 | |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
286 | def __init__(self, *args, **kwargs): |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
287 | # Overwrite the provided run method with our own, to |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
288 | # intercept the thread creation by Qt |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
289 | self._ApplicationRun = self.run |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
290 | self.run = self.__bootstrapQThread |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
291 | |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
292 | super(QThreadWrapper, self).__init__(*args, **kwargs) |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
293 | |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
294 | def __bootstrapQThread(self): |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
295 | newThread = DebugBase(_debugClient) |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
296 | ident = _thread.get_ident() |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
297 | name = 'QtThread-{0}'.format(self.__qtThreadNumber) |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
298 | self.__qtThreadNumber += 1 |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
299 | |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
300 | newThread.id = ident |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
301 | newThread.name = name |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
302 | |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
303 | _debugClient.threads[ident] = newThread |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
304 | |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
305 | frame = sys._getframe() |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
306 | newThread.botframe = frame |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
307 | frame.f_trace = newThread.trace_dispatch |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
308 | # see DebugBase.bootstrap |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
309 | sys.settrace( |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
310 | lambda frame, event, arg: newThread.trace_dispatch) |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
311 | |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
312 | return self._ApplicationRun() |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
313 | |
4332a6751b14
Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5222
diff
changeset
|
314 | module.QThread = QThreadWrapper |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
315 | |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
316 | self.enableImportHooks = True |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
317 | return module |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
318 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
319 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
320 | # |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
321 | # eflag: noqa = M702 |