192 # debugger |
192 # debugger |
193 |
193 |
194 # dictionary of all threads running |
194 # dictionary of all threads running |
195 self.threads = {} |
195 self.threads = {} |
196 |
196 |
197 # the "current" thread, basically the thread we are at a |
197 # the "current" thread, basically the thread we are at a breakpoint |
198 # breakpoint for. |
198 # for. |
199 self.currentThread = self |
199 self.currentThread = self |
200 |
200 |
201 # special objects representing the main scripts thread and frame |
201 # special objects representing the main scripts thread and frame |
202 self.mainThread = self |
202 self.mainThread = self |
203 self.mainFrame = None |
203 self.mainFrame = None |
292 """ |
292 """ |
293 Public method to setup a thread for DebugClient to debug. |
293 Public method to setup a thread for DebugClient to debug. |
294 |
294 |
295 If mainThread is non-zero, then we are attaching to the already |
295 If mainThread is non-zero, then we are attaching to the already |
296 started mainthread of the app and the rest of the args are ignored. |
296 started mainthread of the app and the rest of the args are ignored. |
297 |
|
298 This is just an empty function and is overridden in the threaded |
|
299 debugger. |
|
300 |
297 |
301 @param target the start function of the target thread (i.e. the user |
298 @param target the start function of the target thread (i.e. the user |
302 code) |
299 code) |
303 @param args arguments to pass to target |
300 @param args arguments to pass to target |
304 @param kwargs keyword arguments to pass to target |
301 @param kwargs keyword arguments to pass to target |
524 # set the system exception handling function to ensure, that |
520 # set the system exception handling function to ensure, that |
525 # we report on all unhandled exceptions |
521 # we report on all unhandled exceptions |
526 sys.excepthook = self.__unhandled_exception |
522 sys.excepthook = self.__unhandled_exception |
527 self.__interceptSignals() |
523 self.__interceptSignals() |
528 |
524 |
529 # clear all old breakpoints, they'll get set after we |
525 # clear all old breakpoints, they'll get set after we have |
530 # have started |
526 # started |
531 self.mainThread.clear_all_breaks() |
527 self.mainThread.clear_all_breaks() |
532 |
528 |
533 self.mainThread.tracePython = tracePython |
529 self.mainThread.tracePythonLibs(int(tracePython)) |
534 |
530 |
535 # This will eventually enter a local event loop. |
531 # This will eventually enter a local event loop. |
536 # Note the use of backquotes to cause a repr of self.running. |
532 # Note the use of backquotes to cause a repr of self.running. |
537 # The need for this is on Windows os where backslash is the |
533 # The need for this is on Windows os where backslash is the |
538 # path separator. They will get inadvertantly stripped away |
534 # path separator. They will get inadvertantly stripped away |
571 # set the system exception handling function to ensure, that |
567 # set the system exception handling function to ensure, that |
572 # we report on all unhandled exceptions |
568 # we report on all unhandled exceptions |
573 sys.excepthook = self.__unhandled_exception |
569 sys.excepthook = self.__unhandled_exception |
574 self.__interceptSignals() |
570 self.__interceptSignals() |
575 |
571 |
576 self.mainThread.tracePython = 0 |
572 self.mainThread.tracePythonLibs(0) |
577 |
573 |
578 self.debugMod.__dict__['__file__'] = sys.argv[0] |
574 self.debugMod.__dict__['__file__'] = sys.argv[0] |
579 sys.modules['__main__'] = self.debugMod |
575 sys.modules['__main__'] = self.debugMod |
580 res = 0 |
576 res = 0 |
581 try: |
577 try: |
768 return |
764 return |
769 |
765 |
770 if cmd == DebugProtocol.RequestEval: |
766 if cmd == DebugProtocol.RequestEval: |
771 try: |
767 try: |
772 value = eval( |
768 value = eval( |
773 arg, self.currentThread.getCurrentFrame().f_globals, |
769 arg, |
|
770 self.currentThread.getCurrentFrame().f_globals, |
774 self.currentThread.getFrameLocals(self.framenr)) |
771 self.currentThread.getFrameLocals(self.framenr)) |
775 self.currentThread.storeFrameLocals(self.framenr) |
772 self.currentThread.storeFrameLocals(self.framenr) |
776 except Exception: |
773 except Exception: |
777 # Report the exception and the traceback |
774 # Report the exception and the traceback |
778 try: |
775 try: |
1335 Private method to return the variables of a frame to the debug server. |
1332 Private method to return the variables of a frame to the debug server. |
1336 |
1333 |
1337 @param frmnr distance of frame reported on. 0 is the current frame |
1334 @param frmnr distance of frame reported on. 0 is the current frame |
1338 (int) |
1335 (int) |
1339 @param scope 1 to report global variables, 0 for local variables (int) |
1336 @param scope 1 to report global variables, 0 for local variables (int) |
1340 @param filter the indices of variable types to be filtered (list of |
1337 @param filter the indices of variable types to be filtered |
1341 int) |
1338 (list of int) |
1342 """ |
1339 """ |
1343 if self.currentThread is None: |
1340 if self.currentThread is None: |
1344 return |
1341 return |
1345 |
1342 |
1346 if scope == 0: |
1343 if scope == 0: |
1626 self.write('%s%s\n' % ( |
1623 self.write('%s%s\n' % ( |
1627 DebugProtocol.ResponseVariable, unicode(varlist))) |
1624 DebugProtocol.ResponseVariable, unicode(varlist))) |
1628 |
1625 |
1629 def __formatQtVariable(self, value, vtype): |
1626 def __formatQtVariable(self, value, vtype): |
1630 """ |
1627 """ |
1631 Private method to produce a formated output of a simple Qt4/Qt5 type. |
1628 Private method to produce a formatted output of a simple Qt4/Qt5 type. |
1632 |
1629 |
1633 @param value variable to be formated |
1630 @param value variable to be formatted |
1634 @param vtype type of the variable to be formatted (string) |
1631 @param vtype type of the variable to be formatted (string) |
1635 @return A tuple consisting of a list of formatted variables. Each |
1632 @return A tuple consisting of a list of formatted variables. Each |
1636 variable entry is a tuple of three elements, the variable name, |
1633 variable entry is a tuple of three elements, the variable name, |
1637 its type and value. |
1634 its type and value. |
1638 """ |
1635 """ |
1975 self.mainFrame = None |
1972 self.mainFrame = None |
1976 self.inRawMode = 0 |
1973 self.inRawMode = 0 |
1977 self.debugging = 1 |
1974 self.debugging = 1 |
1978 |
1975 |
1979 self.attachThread(mainThread=1) |
1976 self.attachThread(mainThread=1) |
1980 self.mainThread.tracePython = tracePython |
1977 self.mainThread.tracePythonLibs(tracePython) |
1981 |
1978 |
1982 # set the system exception handling function to ensure, that |
1979 # set the system exception handling function to ensure, that |
1983 # we report on all unhandled exceptions |
1980 # we report on all unhandled exceptions |
1984 sys.excepthook = self.__unhandled_exception |
1981 sys.excepthook = self.__unhandled_exception |
1985 self.__interceptSignals() |
1982 self.__interceptSignals() |
2033 self.write("%s%s|%d\n" % ( |
2030 self.write("%s%s|%d\n" % ( |
2034 DebugProtocol.PassiveStartup, self.running, exceptions)) |
2031 DebugProtocol.PassiveStartup, self.running, exceptions)) |
2035 self.__interact() |
2032 self.__interact() |
2036 |
2033 |
2037 self.attachThread(mainThread=1) |
2034 self.attachThread(mainThread=1) |
2038 self.mainThread.tracePython = tracePython |
2035 self.mainThread.tracePythonLibs(tracePython) |
2039 |
2036 |
2040 # set the system exception handling function to ensure, that |
2037 # set the system exception handling function to ensure, that |
2041 # we report on all unhandled exceptions |
2038 # we report on all unhandled exceptions |
2042 sys.excepthook = self.__unhandled_exception |
2039 sys.excepthook = self.__unhandled_exception |
2043 self.__interceptSignals() |
2040 self.__interceptSignals() |