2033 self.mainThread.set_trace() |
2033 self.mainThread.set_trace() |
2034 |
2034 |
2035 def startProgInDebugger(self, progargs, wd='', host=None, |
2035 def startProgInDebugger(self, progargs, wd='', host=None, |
2036 port=None, exceptions=True, tracePython=False, |
2036 port=None, exceptions=True, tracePython=False, |
2037 redirect=True, passive=True, |
2037 redirect=True, passive=True, |
2038 multiprocessSupport=False, codeStr=""): |
2038 multiprocessSupport=False, codeStr="", |
|
2039 scriptModule=""): |
2039 """ |
2040 """ |
2040 Public method used to start the remote debugger. |
2041 Public method used to start the remote debugger. |
2041 |
2042 |
2042 @param progargs commandline for the program to be debugged |
2043 @param progargs commandline for the program to be debugged |
2043 (list of strings) |
2044 (list of strings) |
2055 @param multiprocessSupport flag indicating to enable multiprocess |
2056 @param multiprocessSupport flag indicating to enable multiprocess |
2056 debugging support |
2057 debugging support |
2057 @type bool |
2058 @type bool |
2058 @param codeStr string containing Python code to execute |
2059 @param codeStr string containing Python code to execute |
2059 @type str |
2060 @type str |
|
2061 @param scriptModule name of a module to be executed as a script |
|
2062 @type str |
2060 @return exit code of the debugged program |
2063 @return exit code of the debugged program |
2061 @rtype int |
2064 @rtype int |
2062 """ |
2065 """ |
2063 if host is None: |
2066 if host is None: |
2064 host = os.getenv('ERICHOST', 'localhost') |
2067 host = os.getenv('ERICHOST', 'localhost') |
2109 # This will eventually enter a local event loop. |
2112 # This will eventually enter a local event loop. |
2110 self.debugMod.__dict__['__file__'] = self.running |
2113 self.debugMod.__dict__['__file__'] = self.running |
2111 sys.modules['__main__'] = self.debugMod |
2114 sys.modules['__main__'] = self.debugMod |
2112 if codeStr: |
2115 if codeStr: |
2113 code = self.__compileCommand(codeStr) |
2116 code = self.__compileCommand(codeStr) |
|
2117 elif scriptModule: |
|
2118 import runpy |
|
2119 modName, modSpec, code = runpy._get_module_details(scriptModule) |
|
2120 self.running = code.co_filename |
|
2121 self.debugMod.__dict__.clear() |
|
2122 self.debugMod.__dict__.update({ |
|
2123 "__name__": "__main__", |
|
2124 "__file__": self.running, |
|
2125 "__package__": modSpec.parent, |
|
2126 "__loader__": modSpec.loader, |
|
2127 "__spec__": modSpec, |
|
2128 "__builtins__": __builtins__, |
|
2129 }) |
2114 else: |
2130 else: |
2115 code = self.__compileFileSource(self.running) |
2131 code = self.__compileFileSource(self.running) |
2116 if code: |
2132 if code: |
2117 res = self.mainThread.run(code, self.debugMod.__dict__, debug=True) |
2133 res = self.mainThread.run(code, self.debugMod.__dict__, debug=True) |
2118 else: |
2134 else: |
2205 passive = False |
2221 passive = False |
2206 del args[0] |
2222 del args[0] |
2207 elif args[0] == '--multiprocess': |
2223 elif args[0] == '--multiprocess': |
2208 multiprocess = True |
2224 multiprocess = True |
2209 del args[0] |
2225 del args[0] |
2210 elif args[0] == '--code': |
2226 elif args[0] in ('-c', '--code'): |
2211 hasCode = True |
2227 codeStr = args[1] |
|
2228 del args[0] |
|
2229 del args[0] |
|
2230 elif args[0] in ('-m', '--module'): |
|
2231 scriptModule = args[1] |
|
2232 del args[0] |
2212 del args[0] |
2233 del args[0] |
2213 elif args[0] == '--': |
2234 elif args[0] == '--': |
2214 del args[0] |
2235 del args[0] |
2215 break |
2236 break |
2216 else: # unknown option |
2237 else: # unknown option |
2228 self.noencoding, |
2249 self.noencoding, |
2229 ) |
2250 ) |
2230 if not self.noencoding: |
2251 if not self.noencoding: |
2231 self.__coding = self.defaultCoding |
2252 self.__coding = self.defaultCoding |
2232 patchNewProcessFunctions(multiprocess, self) |
2253 patchNewProcessFunctions(multiprocess, self) |
2233 if hasCode: |
|
2234 codeStr = args.pop(0) |
|
2235 else: |
|
2236 codeStr = "" |
|
2237 res = self.startProgInDebugger( |
2254 res = self.startProgInDebugger( |
2238 args, wd, host, port, exceptions=exceptions, |
2255 args, wd, host, port, exceptions=exceptions, |
2239 tracePython=tracePython, redirect=redirect, |
2256 tracePython=tracePython, redirect=redirect, |
2240 passive=passive, multiprocessSupport=multiprocess, |
2257 passive=passive, multiprocessSupport=multiprocess, |
2241 codeStr=codeStr |
2258 codeStr=codeStr, scriptModule=scriptModule, |
2242 ) |
2259 ) |
2243 sys.exit(res) |
2260 sys.exit(res) |
2244 else: |
2261 else: |
2245 if sys.argv[1] == '--no-encoding': |
2262 if sys.argv[1] == '--no-encoding': |
2246 self.noencoding = True |
2263 self.noencoding = True |