67 |
69 |
68 def newExecl(path, *args): |
70 def newExecl(path, *args): |
69 """ |
71 """ |
70 Function replacing the 'execl' functions of the os module. |
72 Function replacing the 'execl' functions of the os module. |
71 """ |
73 """ |
72 import os |
|
73 |
|
74 if _shallPatch(): |
74 if _shallPatch(): |
75 args = patchArguments(_debugClient, args) |
75 args = patchArguments(_debugClient, args) |
76 if isPythonProgram(args[0]): |
76 if isPythonProgram(args[0]): |
77 path = args[0] |
77 path = args[0] |
78 return getattr(os, originalName)(path, *args) |
78 return getattr(os, originalName)(path, *args) |
97 |
97 |
98 def newExecv(path, args): |
98 def newExecv(path, args): |
99 """ |
99 """ |
100 Function replacing the 'execv' functions of the os module. |
100 Function replacing the 'execv' functions of the os module. |
101 """ |
101 """ |
102 import os |
|
103 |
|
104 if _shallPatch(): |
102 if _shallPatch(): |
105 args = patchArguments(_debugClient, args) |
103 args = patchArguments(_debugClient, args) |
106 if isPythonProgram(args[0]): |
104 if isPythonProgram(args[0]): |
107 path = args[0] |
105 path = args[0] |
108 return getattr(os, originalName)(path, args) |
106 return getattr(os, originalName)(path, args) |
127 |
125 |
128 def newExecve(path, args, env): |
126 def newExecve(path, args, env): |
129 """ |
127 """ |
130 Function replacing the 'execve' functions of the os module. |
128 Function replacing the 'execve' functions of the os module. |
131 """ |
129 """ |
132 import os |
|
133 |
|
134 if _shallPatch(): |
130 if _shallPatch(): |
135 args = patchArguments(_debugClient, args) |
131 args = patchArguments(_debugClient, args) |
136 if isPythonProgram(args[0]): |
132 if isPythonProgram(args[0]): |
137 path = args[0] |
133 path = args[0] |
138 return getattr(os, originalName)(path, args, env) |
134 return getattr(os, originalName)(path, args, env) |
157 |
153 |
158 def newSpawnl(mode, path, *args): |
154 def newSpawnl(mode, path, *args): |
159 """ |
155 """ |
160 Function replacing the 'spawnl' functions of the os module. |
156 Function replacing the 'spawnl' functions of the os module. |
161 """ |
157 """ |
162 import os |
|
163 |
|
164 args = patchArguments(_debugClient, args) |
158 args = patchArguments(_debugClient, args) |
165 return getattr(os, originalName)(mode, path, *args) |
159 return getattr(os, originalName)(mode, path, *args) |
166 |
160 |
167 return newSpawnl |
161 return newSpawnl |
168 |
162 |
184 |
178 |
185 def newSpawnv(mode, path, args): |
179 def newSpawnv(mode, path, args): |
186 """ |
180 """ |
187 Function replacing the 'spawnv' functions of the os module. |
181 Function replacing the 'spawnv' functions of the os module. |
188 """ |
182 """ |
189 import os |
|
190 |
|
191 args = patchArguments(_debugClient, args) |
183 args = patchArguments(_debugClient, args) |
192 return getattr(os, originalName)(mode, path, args) |
184 return getattr(os, originalName)(mode, path, args) |
193 |
185 |
194 return newSpawnv |
186 return newSpawnv |
195 |
187 |
211 |
203 |
212 def newSpawnve(mode, path, args, env): |
204 def newSpawnve(mode, path, args, env): |
213 """ |
205 """ |
214 Function replacing the 'spawnve' functions of the os module. |
206 Function replacing the 'spawnve' functions of the os module. |
215 """ |
207 """ |
216 import os |
|
217 |
|
218 args = patchArguments(_debugClient, args) |
208 args = patchArguments(_debugClient, args) |
219 return getattr(os, originalName)(mode, path, args, env) |
209 return getattr(os, originalName)(mode, path, args, env) |
220 |
210 |
221 return newSpawnve |
211 return newSpawnve |
222 |
212 |
240 |
230 |
241 def newPosixSpawn(path, argv, env, **kwargs): |
231 def newPosixSpawn(path, argv, env, **kwargs): |
242 """ |
232 """ |
243 Function replacing the 'posix_spawn' functions of the os module. |
233 Function replacing the 'posix_spawn' functions of the os module. |
244 """ |
234 """ |
245 import os |
|
246 |
|
247 argv = patchArguments(_debugClient, argv) |
235 argv = patchArguments(_debugClient, argv) |
248 return getattr(os, originalName)(path, argv, env, **kwargs) |
236 return getattr(os, originalName)(path, argv, env, **kwargs) |
249 |
237 |
250 return newPosixSpawn |
238 return newPosixSpawn |
251 |
239 |
268 def newForkExec(args, *other_args): |
256 def newForkExec(args, *other_args): |
269 """ |
257 """ |
270 Function replacing the 'fork_exec' functions of the _posixsubprocess |
258 Function replacing the 'fork_exec' functions of the _posixsubprocess |
271 module. |
259 module. |
272 """ |
260 """ |
273 import _posixsubprocess |
261 import _posixsubprocess # __IGNORE_WARNING_I103__ |
274 |
262 |
275 if _shallPatch(): |
263 if _shallPatch(): |
276 args = patchArguments(_debugClient, args) |
264 args = patchArguments(_debugClient, args) |
277 return getattr(_posixsubprocess, originalName)(args, *other_args) |
265 return getattr(_posixsubprocess, originalName)(args, *other_args) |
278 |
266 |
295 |
283 |
296 def newFork(): |
284 def newFork(): |
297 """ |
285 """ |
298 Function replacing the 'fork' function of the os module. |
286 Function replacing the 'fork' function of the os module. |
299 """ |
287 """ |
300 import os |
|
301 import sys |
|
302 |
|
303 # A simple fork will result in a new python process |
288 # A simple fork will result in a new python process |
304 isNewPythonProcess = True |
289 isNewPythonProcess = True |
305 frame = sys._getframe() |
290 frame = sys._getframe() |
306 |
291 |
307 multiprocess = _shallPatch() |
292 multiprocess = _shallPatch() |
375 """ |
360 """ |
376 Function replacing the 'CreateProcess' function of the _subprocess |
361 Function replacing the 'CreateProcess' function of the _subprocess |
377 or _winapi module. |
362 or _winapi module. |
378 """ |
363 """ |
379 try: |
364 try: |
380 import _subprocess |
365 import _subprocess # __IGNORE_WARNING_I10__ |
381 except ImportError: |
366 except ImportError: |
382 import _winapi as _subprocess |
367 import _winapi as _subprocess # __IGNORE_WARNING_I10__ |
383 return getattr(_subprocess, originalName)( |
368 return getattr(_subprocess, originalName)( |
384 appName, patchArgumentStringWindows(_debugClient, cmdline), *args |
369 appName, patchArgumentStringWindows(_debugClient, cmdline), *args |
385 ) |
370 ) |
386 |
371 |
387 return newCreateProcess |
372 return newCreateProcess |
400 global _debugClient |
385 global _debugClient |
401 |
386 |
402 if not multiprocessEnabled: |
387 if not multiprocessEnabled: |
403 # return without patching |
388 # return without patching |
404 return |
389 return |
405 |
|
406 import os |
|
407 import sys |
|
408 |
390 |
409 # patch 'os.exec...()' functions |
391 # patch 'os.exec...()' functions |
410 # - patchModule(os, "execl", createExecl) |
392 # - patchModule(os, "execl", createExecl) |
411 # - patchModule(os, "execle", createExecl) |
393 # - patchModule(os, "execle", createExecl) |
412 # - patchModule(os, "execlp", createExecl) |
394 # - patchModule(os, "execlp", createExecl) |
430 patchModule(os, "posix_spawn", createPosixSpawn) |
412 patchModule(os, "posix_spawn", createPosixSpawn) |
431 patchModule(os, "posix_spawnp", createPosixSpawn) |
413 patchModule(os, "posix_spawnp", createPosixSpawn) |
432 |
414 |
433 if isWindowsPlatform(): |
415 if isWindowsPlatform(): |
434 try: |
416 try: |
435 import _subprocess |
417 import _subprocess # __IGNORE_WARNING_I10__ |
436 except ImportError: |
418 except ImportError: |
437 import _winapi as _subprocess |
419 import _winapi as _subprocess # __IGNORE_WARNING_I10__ |
438 patchModule(_subprocess, "CreateProcess", createCreateProcess) |
420 patchModule(_subprocess, "CreateProcess", createCreateProcess) |
439 else: |
421 else: |
440 patchModule(os, "fork", createFork) |
422 patchModule(os, "fork", createFork) |
441 with contextlib.suppress(ImportError): |
423 with contextlib.suppress(ImportError): |
442 import _posixsubprocess |
424 import _posixsubprocess # __IGNORE_WARNING_I10__ |
443 |
425 |
444 patchModule(_posixsubprocess, "fork_exec", createForkExec) |
426 patchModule(_posixsubprocess, "fork_exec", createForkExec) |
445 |
427 |
446 _debugClient = debugClient |
428 _debugClient = debugClient |