eric6/DebugClients/Python/DebugUtilities.py

Sun, 13 Dec 2020 19:54:19 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 13 Dec 2020 19:54:19 +0100
branch
multi_processing
changeset 7873
cb2badbdf26c
parent 7871
eb65864ca038
child 7892
bd6b9e401166
permissions
-rw-r--r--

MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.

4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
3 # Copyright (c) 2015 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing utilities functions for the debug client.
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
5258
cfca063afa07 Optimizations in sending data in AsyncFile. Also thread save.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5178
diff changeset
10 import json
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
11 import os
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
12 import traceback
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
13 import sys
5258
cfca063afa07 Optimizations in sending data in AsyncFile. Also thread save.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5178
diff changeset
14
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 #
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 # Taken from inspect.py of Python 3.4
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 #
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from collections import namedtuple
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 from inspect import iscode, isframe
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 # Create constants for the compiler flags in Include/code.h
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 # We try to get them from dis to avoid duplication, but fall
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 # back to hardcoding so the dependency is optional
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 try:
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 from dis import COMPILER_FLAG_NAMES
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 except ImportError:
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 CO_OPTIMIZED, CO_NEWLOCALS = 0x1, 0x2
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 CO_VARARGS, CO_VARKEYWORDS = 0x4, 0x8
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 CO_NESTED, CO_GENERATOR, CO_NOFREE = 0x10, 0x20, 0x40
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 else:
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 mod_dict = globals()
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 for k, v in COMPILER_FLAG_NAMES.items():
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 mod_dict["CO_" + v] = k
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 ArgInfo = namedtuple('ArgInfo', 'args varargs keywords locals')
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 def getargvalues(frame):
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Function to get information about arguments passed into a
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 particular frame.
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @param frame reference to a frame object to be processed
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @type frame
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @return tuple of four things, where 'args' is a list of the argument names,
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 'varargs' and 'varkw' are the names of the * and ** arguments or None
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 and 'locals' is the locals dictionary of the given frame.
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @exception TypeError raised if the input parameter is not a frame object
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 if not isframe(frame):
4543
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4455
diff changeset
52 raise TypeError('{0!r} is not a frame object'.format(frame))
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 args, varargs, kwonlyargs, varkw = _getfullargs(frame.f_code)
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 return ArgInfo(args + kwonlyargs, varargs, varkw, frame.f_locals)
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 def _getfullargs(co):
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 Protected function to get information about the arguments accepted
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 by a code object.
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @param co reference to a code object to be processed
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 @type code
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @return tuple of four things, where 'args' and 'kwonlyargs' are lists of
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 argument names, and 'varargs' and 'varkw' are the names of the
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 * and ** arguments or None.
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @exception TypeError raised if the input parameter is not a code object
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if not iscode(co):
4543
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4455
diff changeset
71 raise TypeError('{0!r} is not a code object'.format(co))
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 nargs = co.co_argcount
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 names = co.co_varnames
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 nkwargs = co.co_kwonlyargcount
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 args = list(names[:nargs])
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 kwonlyargs = list(names[nargs:nargs + nkwargs])
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 nargs += nkwargs
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 varargs = None
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 if co.co_flags & CO_VARARGS:
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 varargs = co.co_varnames[nargs]
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 nargs = nargs + 1
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 varkw = None
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if co.co_flags & CO_VARKEYWORDS:
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 varkw = co.co_varnames[nargs]
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 return args, varargs, kwonlyargs, varkw
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
90 def formatargvalues(args, varargs, varkw, localsDict,
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 formatarg=str,
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 formatvarargs=lambda name: '*' + name,
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 formatvarkw=lambda name: '**' + name,
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 formatvalue=lambda value: '=' + repr(value)):
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 Function to format an argument spec from the 4 values returned
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 by getargvalues.
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 @param args list of argument names
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 @type list of str
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 @param varargs name of the variable arguments
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 @type str
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 @param varkw name of the keyword arguments
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 @type str
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
105 @param localsDict reference to the local variables dictionary
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @type dict
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 @keyparam formatarg argument formatting function
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 @type func
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 @keyparam formatvarargs variable arguments formatting function
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 @type func
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 @keyparam formatvarkw keyword arguments formatting function
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 @type func
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @keyparam formatvalue value formating functtion
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @type func
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @return formatted call signature
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @rtype str
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 specs = []
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 for i in range(len(args)):
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 name = args[i]
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
121 specs.append(formatarg(name) + formatvalue(localsDict[name]))
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 if varargs:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
123 specs.append(formatvarargs(varargs) + formatvalue(localsDict[varargs]))
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 if varkw:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
125 specs.append(formatvarkw(varkw) + formatvalue(localsDict[varkw]))
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 argvalues = '(' + ', '.join(specs) + ')'
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
127 if '__return__' in localsDict:
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
128 argvalues += " -> " + formatvalue(localsDict['__return__'])
4455
ca13a6f6c452 Prepared the Python3 debug client for some obsolescences of the inspect.py module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 return argvalues
4543
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4455
diff changeset
130
5129
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
131
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132 def prepareJsonCommand(method, params):
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
133 """
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
134 Function to prepare a single command or response for transmission to
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135 the IDE.
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
136
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
137 @param method command or response name to be sent
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
138 @type str
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
139 @param params dictionary of named parameters for the command or response
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
140 @type dict
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
141 @return prepared JSON command or response string
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
142 @rtype str
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
143 """
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
144 commandDict = {
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
145 "jsonrpc": "2.0",
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
146 "method": method,
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
147 "params": params,
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
148 }
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
149 return json.dumps(commandDict) + '\n'
e4ab234cf071 Cleaned up the modified code for the modernized debugger interface (Python3 variant).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
150
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
151 ###########################################################################
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
152 ## Things related to monkey patching below
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
153 ###########################################################################
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
154
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
155
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
156 PYTHON_NAMES = ["python", "pypy"]
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
157
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
158
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
159 def isWindowsPlatform():
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
160 """
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
161 Function to check, if this is a Windows platform.
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
162
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
163 @return flag indicating Windows platform
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
164 @rtype bool
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
165 """
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
166 return sys.platform.startswith(("win", "cygwin"))
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
167
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
168
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
169 def isExecutable(program):
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
170 """
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
171 Function to check, if the given program is executable.
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
172
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
173 @param program program path to be checked
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
174 @type str
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
175 @return flag indicating an executable program
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
176 @rtype bool
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
177 """
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
178 return os.access(os.path.abspath(program), os.X_OK)
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
179
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
180
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
181 def startsWithShebang(program):
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
182 """
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
183 Function to check, if the given program start with a Shebang line.
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
184
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
185 @param program program path to be checked
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
186 @type str
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
187 @return flag indicating an existing and valid shebang line
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
188 @rtype bool
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
189 """
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
190 try:
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
191 with open(program) as f:
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
192 for line in f:
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
193 line = line.strip()
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
194 if line:
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
195 for name in PYTHON_NAMES:
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
196 if line.startswith('#!/usr/bin/env {0}'.format(name)):
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
197 return True
7873
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
198 elif line.startswith('#!') and name in line:
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
199 return True
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
200 return False
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
201 except UnicodeDecodeError:
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
202 return False
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
203 except Exception:
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
204 traceback.print_exc()
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
205 return False
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
206
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
207
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
208 def isPythonProgram(program):
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
209 """
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
210 Function to check, if the given program is a Python interpreter or
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
211 program.
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
212
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
213 @param program program to be checked
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
214 @type str
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
215 @return flag indicating a Python interpreter or program
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
216 @rtype bool
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
217 """
7421
4a9900aef04e Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7420
diff changeset
218 if not program:
4a9900aef04e Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7420
diff changeset
219 return False
4a9900aef04e Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7420
diff changeset
220
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
221 prog = os.path.basename(program).lower()
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
222 for pyname in PYTHON_NAMES:
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
223 if pyname in prog:
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
224 return True
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
225
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
226 return (
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
227 not isWindowsPlatform() and
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
228 isExecutable(program) and
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
229 startsWithShebang(program)
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
230 )
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
231
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
232
7871
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
233 def removeQuotesFromArgs(args):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
234 """
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
235 Function to remove quotes from the arguments list.
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
236
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
237 @param args list of arguments
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
238 @type list of str
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
239 @return list of unquoted strings
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
240 @rtype list of str
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
241 """
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
242 if isWindowsPlatform():
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
243 newArgs = []
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
244 for x in args:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
245 if len(x) > 1 and x.startswith('"') and x.endswith('"'):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
246 x = x[1:-1]
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
247 newArgs.append(x)
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
248 return newArgs
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
249 else:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
250 return args
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
251
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
252
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
253 def quoteArgs(args):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
254 """
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
255 Function to quote the given list of arguments.
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
256
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
257 @param args list of arguments to be quoted
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
258 @type list of str
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
259 @return list of quoted arguments
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
260 @rtype list of str
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
261 """
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
262 if isWindowsPlatform():
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
263 quotedArgs = []
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
264 for x in args:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
265 if x.startswith('"') and x.endswith('"'):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
266 quotedArgs.append(x)
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
267 else:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
268 if ' ' in x:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
269 x = x.replace('"', '\\"')
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
270 quotedArgs.append('"{0}"'.format(x))
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
271 else:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
272 quotedArgs.append(x)
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
273 return quotedArgs
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
274 else:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
275 return args
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
276
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
277
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
278 def patchArguments(debugClient, arguments, noRedirect=False):
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
279 """
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
280 Function to patch the arguments given to start a program in order to
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
281 execute it in our debugger.
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
282
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
283 @param debugClient reference to the debug client object
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
284 @type DebugClient
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
285 @param arguments list of program arguments
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
286 @type list of str
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
287 @param noRedirect flag indicating to not redirect stdin and stdout
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
288 @type bool
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
289 @return modified argument list
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
290 @rtype list of str
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
291 """
7873
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
292 debugClientScript = os.path.join(
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
293 os.path.dirname(__file__), "DebugClient.py")
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
294 if debugClientScript in arguments:
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
295 # it is already patched
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
296 return arguments
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
297
7422
9a008ab4811b Started implementing the patching of the os module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7421
diff changeset
298 args = list(arguments[:]) # create a copy of the arguments list
7871
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
299 args = removeQuotesFromArgs(args)
7420
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
300
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
301 # support for shebang line
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
302 program = os.path.basename(args[0]).lower()
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
303 for pyname in PYTHON_NAMES:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
304 if pyname in program:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
305 break
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
306 else:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
307 if not isWindowsPlatform() and startsWithShebang(args[0]):
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
308 # insert our interpreter as first argument
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
309 args.insert(0, sys.executable)
7873
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
310 elif isWindowsPlatform() and args[0].lower().endswith(".py"):
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
311 # it is a Python script; insert our interpreter as first argument
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
312 args.insert(0, sys.executable)
7420
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
313
7871
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
314 # check for -m invocation => debugging not supported yet
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
315 if "-m" in args:
7420
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
316 cm_position = args.index("-m")
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
317 else:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
318 cm_position = 0
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
319 if cm_position > 0:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
320 # check if it belongs to the interpreter or program
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
321 for pos in range(1, len(args)):
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
322 if not args[pos].startswith("-"):
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
323 # first argument not starting with '-' is the program
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
324 found = True
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
325 break
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
326 else:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
327 found = False
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
328 if found and cm_position < pos:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
329 # it belongs to the interpreter
7871
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
330 return quoteArgs(arguments)
7420
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
331
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
332 # extract list of interpreter arguments, i.e. all arguments before the
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
333 # first one not starting with '-'.
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
334 interpreter = args.pop(0)
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
335 interpreterArgs = []
7871
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
336 hasCode = False
7420
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
337 while args:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
338 if args[0].startswith("-"):
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
339 if args[0] in ("-W", "-X"):
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
340 # take two elements off the list
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
341 interpreterArgs.append(args.pop(0))
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
342 interpreterArgs.append(args.pop(0))
7871
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
343 elif args[0] == "-c":
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
344 # -c indicates code to be executed and ends the
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
345 # arguments list
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
346 args.pop(0)
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
347 hasCode = True
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
348 break
7420
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
349 else:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
350 interpreterArgs.append(args.pop(0))
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
351 else:
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
352 break
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
353
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
354 (wd, host, port, exceptions, tracePython, redirect, noencoding
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
355 ) = debugClient.startOptions[:7]
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
356
7420
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
357 modifiedArguments = [interpreter]
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
358 modifiedArguments.extend(interpreterArgs)
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
359 modifiedArguments.extend([
7873
cb2badbdf26c MultiProcessDebugExtension: commented out the support for os.exec, os.spawn and os.posix_spawn.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7871
diff changeset
360 debugClientScript,
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
361 "-h", host,
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
362 "-p", str(port),
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
363 "--no-passive",
7420
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
364 ])
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
365
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
366 if wd:
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
367 modifiedArguments.extend(["-w", wd])
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
368 if not exceptions:
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
369 modifiedArguments.append("-e")
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
370 if tracePython:
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
371 modifiedArguments.append("-t")
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
372 if noRedirect or not redirect:
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
373 modifiedArguments.append("-n")
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
374 if noencoding:
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
375 modifiedArguments.append("--no-encoding")
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
376 if debugClient.multiprocessSupport:
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
377 modifiedArguments.append("--multiprocess")
7871
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
378 if hasCode:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
379 modifiedArguments.append("--code")
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
380 modifiedArguments.append("--")
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
381 # end the arguments for DebugClient
7419
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
382
9c1163735448 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412
diff changeset
383 # append the arguments for the program to be debugged
7420
0d596bb4a60d Added multi process support for programs with a shebang line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419
diff changeset
384 modifiedArguments.extend(args)
7871
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
385 modifiedArguments = quoteArgs(modifiedArguments)
7412
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
386
0a995393d2ba Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
387 return modifiedArguments
7871
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
388
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
389
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
390 def stringToArgumentsWindows(args):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
391 """
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
392 Function to prepare a string of arguments for Windows platform.
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
393
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
394 @param args list of command arguments
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
395 @type str
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
396 @return list of command arguments
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
397 @rtype list of str
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
398 @exception RuntimeError raised to indicate an illegal arguments parsing
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
399 condition
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
400 """
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
401 # see http:#msdn.microsoft.com/en-us/library/a1y7w461.aspx
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
402 result = []
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
403
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
404 DEFAULT = 0
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
405 ARG = 1
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
406 IN_DOUBLE_QUOTE = 2
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
407
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
408 state = DEFAULT
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
409 backslashes = 0
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
410 buf = ''
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
411
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
412 argsLen = len(args)
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
413 for i in range(argsLen):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
414 ch = args[i]
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
415 if ch == '\\':
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
416 backslashes += 1
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
417 continue
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
418 elif backslashes != 0:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
419 if ch == '"':
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
420 while backslashes >= 2:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
421 backslashes -= 2
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
422 buf += '\\'
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
423 if backslashes == 1:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
424 if state == DEFAULT:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
425 state = ARG
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
426
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
427 buf += '"'
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
428 backslashes = 0
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
429 continue
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
430 else:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
431 # false alarm, treat passed backslashes literally...
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
432 if state == DEFAULT:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
433 state = ARG
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
434
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
435 while backslashes > 0:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
436 backslashes -= 1
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
437 buf += '\\'
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
438
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
439 if ch in (' ', '\t'):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
440 if state == DEFAULT:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
441 # skip
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
442 continue
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
443 elif state == ARG:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
444 state = DEFAULT
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
445 result.append(buf)
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
446 buf = ''
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
447 continue
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
448
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
449 if state in (DEFAULT, ARG):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
450 if ch == '"':
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
451 state = IN_DOUBLE_QUOTE
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
452 else:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
453 state = ARG
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
454 buf += ch
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
455
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
456 elif state == IN_DOUBLE_QUOTE:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
457 if ch == '"':
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
458 if i + 1 < argsLen and args[i + 1] == '"':
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
459 # Undocumented feature in Windows:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
460 # Two consecutive double quotes inside a double-quoted
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
461 # argument are interpreted as a single double quote.
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
462 buf += '"'
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
463 i += 1
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
464 elif len(buf) == 0:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
465 result.append("\"\"")
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
466 state = DEFAULT
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
467 else:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
468 state = ARG
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
469 else:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
470 buf += ch
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
471
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
472 else:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
473 raise RuntimeError('Illegal condition')
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
474
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
475 if len(buf) > 0 or state != DEFAULT:
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
476 result.append(buf)
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
477
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
478 return result
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
479
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
480
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
481 def patchArgumentStringWindows(debugClient, argStr):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
482 """
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
483 Function to patch an argument string for Windows.
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
484
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
485 @param debugClient reference to the debug client object
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
486 @type DebugClient
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
487 @param argStr argument string
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
488 @type str
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
489 @return patched argument string
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
490 @rtype str
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
491 """
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
492 args = stringToArgumentsWindows(argStr)
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
493 if not args or not isPythonProgram(args[0]):
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
494 return argStr
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
495
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
496 argStr = ' '.join(patchArguments(debugClient, args))
eb65864ca038 Added some more process creation function overrides.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7646
diff changeset
497 return argStr

eric ide

mercurial