eric6/DebugClients/Python/ModuleLoader.py

Sun, 05 Jul 2020 11:11:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 05 Jul 2020 11:11:24 +0200
branch
multi_processing
changeset 7646
39e3db2b4936
parent 7563
b0d6b63f2843
child 7887
c1588f5a83e9
permissions
-rw-r--r--

Merged with default to track recent development.

7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de>
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an import hook patching modules to support debugging.
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import sys
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import importlib
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
13 from QProcessExtension import patchQProcess
7424
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
14 from SubprocessExtension import patchSubprocess
7563
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
15 from MultiprocessingExtension import patchMultiprocessing
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
16
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class ModuleLoader(object):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class implementing an import hook patching modules to support debugging.
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 def __init__(self, debugClient):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @param debugClient reference to the debug client object
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @type DebugClient
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.__dbgClient = debugClient
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 self.__enableImportHooks = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 # reset already imported thread module to apply hooks at next import
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 for moduleName in ("thread", "_thread", "threading"):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 if moduleName in sys.modules:
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 del sys.modules[moduleName]
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.__modulesToPatch = (
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
39 'thread', '_thread', 'threading',
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
40 'greenlet',
7424
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
41 'subprocess',
7563
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
42 'multiprocessing',
7646
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7563
diff changeset
43 'PyQt5.QtCore',
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7563
diff changeset
44 'PySide2.QtCore',
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 )
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 sys.meta_path.insert(0, self)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 def __loadModule(self, fullname):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
51 Private method to load a module.
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @param fullname name of the module to be loaded
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @type str
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @return reference to the loaded module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @rtype module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 module = importlib.import_module(fullname)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 sys.modules[fullname] = module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 ## Add hook for _thread.start_new_thread
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 if (
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 fullname in ('thread', '_thread') and
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 not hasattr(module, 'eric6_patched')
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 module.eric6_patched = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.__dbgClient.patchPyThread(module)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 ## Add hook for threading.run()
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 elif (
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 fullname == "threading" and
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 not hasattr(module, 'eric6_patched')
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 module.eric6_patched = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__dbgClient.patchPyThreading(module)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 ## greenlet support
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 elif (
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 fullname == 'greenlet' and
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 not hasattr(module, 'eric6_patched')
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 if self.__dbgClient.patchGreenlet(module):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 module.eric6_patched = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
7424
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
85 ## Add hook for subprocess.Popen()
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
86 elif (
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
87 fullname == 'subprocess' and
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
88 not hasattr(module, 'eric6_patched')
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
89 ):
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
90 module.eric6_patched = True
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
91 patchSubprocess(module, self.__dbgClient)
7563
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
92
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
93 ## Add hook for multiprocessing.Process
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
94 elif (
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
95 fullname == 'multiprocessing' and
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
96 not hasattr(module, 'eric6_patched')
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
97 ):
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
98 module.eric6_patched = True
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
99 patchMultiprocessing(module, self.__dbgClient)
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
100
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
101 ## Add hook for *.QThread and *.QProcess
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 elif (
7646
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7563
diff changeset
103 fullname in ('PyQt5.QtCore', 'PySide2.QtCore') and
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 not hasattr(module, 'eric6_patched')
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 module.eric6_patched = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 self.__dbgClient.patchQThread(module)
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7408
diff changeset
108 patchQProcess(module, self.__dbgClient)
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.__enableImportHooks = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 return module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 if sys.version_info >= (3, 4):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 def find_spec(self, fullname, path, target=None):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 Public method returning the module spec.
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @param fullname name of the module to be loaded
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @type str
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 @param path path to resolve the module name
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 @type str
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @param target module object to use for a more educated guess
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 about what spec to return
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 @type module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 @return module spec object pointing to the module loader
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 @type ModuleSpec
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 if fullname in sys.modules or not self.__dbgClient.debugging:
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 return None
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 if (
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 fullname in self.__modulesToPatch and
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 self.__enableImportHooks
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 # Disable hook to be able to import original module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 self.__enableImportHooks = False
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 return importlib.machinery.ModuleSpec(fullname, self)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 return None
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 def create_module(self, spec):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 Public method to create a module based on the passed in spec.
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 @param spec module spec object for loading the module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 @type ModuleSpec
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 @return created and patched module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 @rtype module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 return self.__loadModule(spec.name)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 def exec_module(self, module):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 """
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
154 Public method to execute the created module.
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 @param module module to be executed
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @type module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 pass
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 else:
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 def find_module(self, fullname, path=None):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 Public method returning the module loader.
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 @param fullname name of the module to be loaded
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 @type str
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 @param path path to resolve the module name
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 @type str
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 @return module loader object
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 @rtype object
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 if fullname in sys.modules or not self.__dbgClient.debugging:
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 return None
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 if (
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 fullname in self.__modulesToPatch and
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 self.__enableImportHooks
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 # Disable hook to be able to import original module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self.__enableImportHooks = False
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 return self
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 return None
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 def load_module(self, fullname):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 Public method to load a module.
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 @param fullname name of the module to be loaded
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 @type str
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 @return reference to the loaded module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 @rtype module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 return self.__loadModule(fullname)

eric ide

mercurial