eric6/DebugClients/Python/MultiProcessDebugExtension.py

Sun, 18 Oct 2020 12:35:30 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 18 Oct 2020 12:35:30 +0200
branch
multi_processing
changeset 7802
eefe954f01e8
parent 7646
39e3db2b4936
child 7871
eb65864ca038
permissions
-rw-r--r--

Merged with default branch.

7422
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2002 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a function to patch the process creation functions to
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 support multiprocess debugging.
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
7802
eefe954f01e8 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
12 from DebugUtilities import patchArguments, isPythonProgram
7422
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 _debugClient = None
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 def patchModule(module, functionName, createFunction):
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Function to replace a function of a module with a modified one.
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @param module reference to the module
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 @type types.ModuleType
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 @param functionName name of the function to be replaced
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @type str
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @param createFunction function creating the replacement
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @type types.FunctionType
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 if hasattr(module, functionName):
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 originalName = 'original_' + functionName
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 if not hasattr(module, originalName):
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 setattr(module, originalName, getattr(module, functionName))
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 setattr(module, functionName, createFunction(originalName))
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 def createExecl(originalName):
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 Function to patch the 'execl' process creation functions.
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 <ul>
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 <li>os.execl(path, arg0, arg1, ...)</li>
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 <li>os.execle(path, arg0, arg1, ..., env)</li>
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 <li>os.execlp(file, arg0, arg1, ...)</li>
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 <li>os.execlpe(file, arg0, arg1, ..., env)</li>
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 </ul>
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 def newExecl(path, *args):
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Function replacing the 'execl' functions of the os module.
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 print(args)
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 import os
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 if (
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 _debugClient.debugging and
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 _debugClient.multiprocessSupport
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 ):
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 args = patchArguments(_debugClient, args)
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 if isPythonProgram(args[0]):
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 path = args[0]
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 print(args)
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 return getattr(os, originalName)(path, *args)
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 return newExecl
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
7646
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7422
diff changeset
63
7422
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 def patchNewProcessFunctions(multiprocessEnabled, debugClient):
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 Function to patch the process creation functions to support multiprocess
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 debugging.
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param multiprocessEnabled flag indicating multiprocess support
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @type bool
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @param debugClient reference to the debug client object
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @type DebugClient
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 global _debugClient
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 if not multiprocessEnabled:
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 # return without patching
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 return
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 import os
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 # patch 'os.exec...()' functions
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 patchModule(os, "execl", createExecl)
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 patchModule(os, "execle", createExecl)
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 patchModule(os, "execlp", createExecl)
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 patchModule(os, "execlpe", createExecl)
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 # TODO: implement patching of the various functions of the os module
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 _debugClient = debugClient

eric ide

mercurial