13 import atexit |
13 import atexit |
14 import inspect |
14 import inspect |
15 import ctypes |
15 import ctypes |
16 from inspect import CO_GENERATOR |
16 from inspect import CO_GENERATOR |
17 |
17 |
18 from DebugProtocol import ResponseClearWatch, ResponseClearBreak, \ |
|
19 ResponseLine, ResponseSyntax, ResponseException, CallTrace |
|
20 from DebugUtilities import getargvalues, formatargvalues |
18 from DebugUtilities import getargvalues, formatargvalues |
21 |
19 |
22 gRecursionLimit = 64 |
20 gRecursionLimit = 64 |
23 |
21 |
24 |
22 |
208 fr = toFrame |
206 fr = toFrame |
209 toStr = "{0}:{1}:{2}".format( |
207 toStr = "{0}:{1}:{2}".format( |
210 self._dbgClient.absPath(self.fix_frame_filename(fr)), |
208 self._dbgClient.absPath(self.fix_frame_filename(fr)), |
211 fr.f_lineno, |
209 fr.f_lineno, |
212 fr.f_code.co_name) |
210 fr.f_code.co_name) |
213 self._dbgClient.write("{0}{1}@@{2}@@{3}\n".format( |
211 self._dbgClient.sendCallTrace(event, fromStr, toStr) |
214 CallTrace, event[0], fromStr, toStr)) |
|
215 |
212 |
216 def trace_dispatch(self, frame, event, arg): |
213 def trace_dispatch(self, frame, event, arg): |
217 """ |
214 """ |
218 Public method reimplemented from bdb.py to do some special things. |
215 Public method reimplemented from bdb.py to do some special things. |
219 |
216 |
443 Private method called to clear a temporary watch expression. |
440 Private method called to clear a temporary watch expression. |
444 |
441 |
445 @param cond expression of the watch expression to be cleared (string) |
442 @param cond expression of the watch expression to be cleared (string) |
446 """ |
443 """ |
447 self.clear_watch(cond) |
444 self.clear_watch(cond) |
448 self._dbgClient.write('{0}{1}\n'.format(ResponseClearWatch, cond)) |
445 self._dbgClient.sendClearTemporaryWatch(cond) |
449 |
446 |
450 def __effective(self, frame): |
447 def __effective(self, frame): |
451 """ |
448 """ |
452 Private method to determine, if a watch expression is effective. |
449 Private method to determine, if a watch expression is effective. |
453 |
450 |
580 |
577 |
581 @param filename name of the file the bp belongs to |
578 @param filename name of the file the bp belongs to |
582 @param lineno linenumber of the bp |
579 @param lineno linenumber of the bp |
583 """ |
580 """ |
584 self.clear_break(filename, lineno) |
581 self.clear_break(filename, lineno) |
585 self._dbgClient.write('{0}{1},{2:d}\n'.format( |
582 self._dbgClient.sendClearTemporaryBreakpoint(filename, lineno) |
586 ResponseClearBreak, filename, lineno)) |
|
587 |
583 |
588 def getStack(self): |
584 def getStack(self): |
589 """ |
585 """ |
590 Public method to get the stack. |
586 Public method to get the stack. |
591 |
587 |
642 if self._dbgClient.mainFrame is None: |
638 if self._dbgClient.mainFrame is None: |
643 if fn != self._dbgClient.getRunning(): |
639 if fn != self._dbgClient.getRunning(): |
644 return |
640 return |
645 fr = frame |
641 fr = frame |
646 while (fr is not None and |
642 while (fr is not None and |
647 fr.f_code != self._dbgClient.handleLine.__code__): |
643 fr.f_code not in [ |
|
644 self._dbgClient.handleLine.__code__, |
|
645 self._dbgClient.handleJsonCommand.__code__]): |
648 self._dbgClient.mainFrame = fr |
646 self._dbgClient.mainFrame = fr |
649 fr = fr.f_back |
647 fr = fr.f_back |
650 |
648 |
651 self.currentFrame = frame |
649 self.currentFrame = frame |
652 |
650 |
685 else: |
683 else: |
686 fr = fr.f_back |
684 fr = fr.f_back |
687 |
685 |
688 self.__isBroken = True |
686 self.__isBroken = True |
689 |
687 |
690 self._dbgClient.write('{0}{1}\n'.format(ResponseLine, str(stack))) |
688 self._dbgClient.sendResponseLine(stack) |
691 self._dbgClient.eventLoop() |
689 self._dbgClient.eventLoop() |
692 |
690 |
693 def user_exception(self, frame, excinfo, unhandled=False): |
691 def user_exception(self, frame, excinfo, unhandled=False): |
694 """ |
692 """ |
695 Public method reimplemented to report an exception to the debug server. |
693 Public method reimplemented to report an exception to the debug server. |
722 |
720 |
723 if exctype in [SyntaxError, IndentationError]: |
721 if exctype in [SyntaxError, IndentationError]: |
724 try: |
722 try: |
725 message = str(excval) |
723 message = str(excval) |
726 filename = excval.filename |
724 filename = excval.filename |
727 linenr = excval.lineno |
725 lineno = excval.lineno |
728 charnr = excval.offset |
726 charno = excval.offset |
|
727 realSyntaxError = os.path.exists(filename) |
729 except (AttributeError, ValueError): |
728 except (AttributeError, ValueError): |
730 exclist = [] |
729 message = "" |
|
730 filename = "" |
|
731 lineno = 0 |
|
732 charno = 0 |
731 realSyntaxError = True |
733 realSyntaxError = True |
732 else: |
|
733 exclist = [message, [filename, linenr, charnr]] |
|
734 realSyntaxError = os.path.exists(filename) |
|
735 |
734 |
736 if realSyntaxError: |
735 if realSyntaxError: |
737 self._dbgClient.write("{0}{1}\n".format( |
736 self._dbgClient.sendSyntaxError( |
738 ResponseSyntax, str(exclist))) |
737 message, filename, lineno, charno) |
739 self._dbgClient.eventLoop() |
738 self._dbgClient.eventLoop() |
740 return |
739 return |
741 |
740 |
742 exctype = self.__extractExceptionName(exctype) |
741 exctype = self.__extractExceptionName(exctype) |
743 |
742 |
746 |
745 |
747 if unhandled: |
746 if unhandled: |
748 exctypetxt = "unhandled {0!s}".format(str(exctype)) |
747 exctypetxt = "unhandled {0!s}".format(str(exctype)) |
749 else: |
748 else: |
750 exctypetxt = str(exctype) |
749 exctypetxt = str(exctype) |
751 try: |
750 |
752 exclist = [exctypetxt, str(excval)] |
751 stack = [] |
753 except TypeError: |
|
754 exclist = [exctypetxt, str(excval)] |
|
755 |
|
756 if exctb: |
752 if exctb: |
757 frlist = self.__extract_stack(exctb) |
753 frlist = self.__extract_stack(exctb) |
758 frlist.reverse() |
754 frlist.reverse() |
759 |
755 |
760 self.currentFrame = frlist[0] |
756 self.currentFrame = frlist[0] |
781 except Exception: |
777 except Exception: |
782 fargs = "" |
778 fargs = "" |
783 else: |
779 else: |
784 fargs = "" |
780 fargs = "" |
785 |
781 |
786 exclist.append([filename, linenr, ffunc, fargs]) |
782 stack.append([filename, linenr, ffunc, fargs]) |
787 |
783 |
788 self._dbgClient.write("{0}{1}\n".format( |
784 self._dbgClient.sendException(exctypetxt, str(excval), stack) |
789 ResponseException, str(exclist))) |
|
790 |
785 |
791 if exctb is None: |
786 if exctb is None: |
792 return |
787 return |
793 |
788 |
794 self._dbgClient.eventLoop() |
789 self._dbgClient.eventLoop() |