Debugger/DebuggerInterfacePython.py

changeset 711
8cd4f7a574a2
parent 564
b3d966393ba9
child 788
5b1b59777460
equal deleted inserted replaced
710:5a18249d68aa 711:8cd4f7a574a2
7 Module implementing the Python debugger interface for the debug server. 7 Module implementing the Python debugger interface for the debug server.
8 """ 8 """
9 9
10 import sys 10 import sys
11 import os 11 import os
12 import re
12 13
13 from PyQt4.QtCore import * 14 from PyQt4.QtCore import *
14 from PyQt4.QtGui import QInputDialog 15 from PyQt4.QtGui import QInputDialog
15 16
16 from E5Gui.E5Application import e5App 17 from E5Gui.E5Application import e5App
70 self.queue = [] 71 self.queue = []
71 # set default values for capabilities of clients 72 # set default values for capabilities of clients
72 self.clientCapabilities = ClientDefaultCapabilities 73 self.clientCapabilities = ClientDefaultCapabilities
73 74
74 self.codec = QTextCodec.codecForName(Preferences.getSystem("StringEncoding")) 75 self.codec = QTextCodec.codecForName(Preferences.getSystem("StringEncoding"))
76
77 self.__unicodeRe = re.compile(r"""\bu(["'])""")
75 78
76 if passive: 79 if passive:
77 # set translation function 80 # set translation function
78 if Preferences.getDebugger("PathTranslation"): 81 if Preferences.getDebugger("PathTranslation"):
79 self.translateRemote = \ 82 self.translateRemote = \
759 eoc = line.find('<') + 1 762 eoc = line.find('<') + 1
760 boc = line.find('>') 763 boc = line.find('>')
761 764
762 if boc >= 0 and eoc > boc: 765 if boc >= 0 and eoc > boc:
763 resp = line[boc:eoc] 766 resp = line[boc:eoc]
767 evalArg = self.__unicodeRe.sub(r"\1", line[eoc:-1])
764 768
765 if resp == ResponseLine or resp == ResponseStack: 769 if resp == ResponseLine or resp == ResponseStack:
766 stack = eval(line[eoc:-1]) 770 stack = eval(evalArg)
767 for s in stack: 771 for s in stack:
768 s[0] = self.translate(s[0], True) 772 s[0] = self.translate(s[0], True)
769 cf = stack[0] 773 cf = stack[0]
770 if self.__autoContinue: 774 if self.__autoContinue:
771 self.__autoContinue = False 775 self.__autoContinue = False
775 resp == ResponseStack) 779 resp == ResponseStack)
776 self.debugServer.signalClientStack(stack) 780 self.debugServer.signalClientStack(stack)
777 continue 781 continue
778 782
779 if resp == ResponseThreadList: 783 if resp == ResponseThreadList:
780 currentId, threadList = eval(line[eoc:-1]) 784 currentId, threadList = eval(evalArg)
781 self.debugServer.signalClientThreadList(currentId, threadList) 785 self.debugServer.signalClientThreadList(currentId, threadList)
782 continue 786 continue
783 787
784 if resp == ResponseThreadSet: 788 if resp == ResponseThreadSet:
785 self.debugServer.signalClientThreadSet() 789 self.debugServer.signalClientThreadSet()
786 continue 790 continue
787 791
788 if resp == ResponseVariables: 792 if resp == ResponseVariables:
789 vlist = eval(line[eoc:-1]) 793 vlist = eval(evalArg)
790 scope = vlist[0] 794 scope = vlist[0]
791 try: 795 try:
792 variables = vlist[1:] 796 variables = vlist[1:]
793 except IndexError: 797 except IndexError:
794 variables = [] 798 variables = []
795 self.debugServer.signalClientVariables(scope, variables) 799 self.debugServer.signalClientVariables(scope, variables)
796 continue 800 continue
797 801
798 if resp == ResponseVariable: 802 if resp == ResponseVariable:
799 vlist = eval(line[eoc:-1]) 803 vlist = eval(evalArg)
800 scope = vlist[0] 804 scope = vlist[0]
801 try: 805 try:
802 variables = vlist[1:] 806 variables = vlist[1:]
803 except IndexError: 807 except IndexError:
804 variables = [] 808 variables = []
812 if resp == ResponseContinue: 816 if resp == ResponseContinue:
813 self.debugServer.signalClientStatement(True) 817 self.debugServer.signalClientStatement(True)
814 continue 818 continue
815 819
816 if resp == ResponseException: 820 if resp == ResponseException:
817 exc = line[eoc:-1] 821 exc = self.translate(evalArg, True)
818 exc = self.translate(exc, True)
819 try: 822 try:
820 exclist = eval(exc) 823 exclist = eval(exc)
821 exctype = exclist[0] 824 exctype = exclist[0]
822 excmessage = exclist[1] 825 excmessage = exclist[1]
823 stack = exclist[2:] 826 stack = exclist[2:]
827 stack = [] 830 stack = []
828 self.debugServer.signalClientException(exctype, excmessage, stack) 831 self.debugServer.signalClientException(exctype, excmessage, stack)
829 continue 832 continue
830 833
831 if resp == ResponseSyntax: 834 if resp == ResponseSyntax:
832 exc = line[eoc:-1] 835 exc = self.translate(evalArg, True)
833 exc = self.translate(exc, True)
834 try: 836 try:
835 message, (fn, ln, cn) = eval(exc) 837 message, (fn, ln, cn) = eval(exc)
836 if fn is None: 838 if fn is None:
837 fn = '' 839 fn = ''
838 except (IndexError, ValueError): 840 except (IndexError, ValueError):
844 cn = 0 846 cn = 0
845 self.debugServer.signalClientSyntaxError(message, fn, ln, cn) 847 self.debugServer.signalClientSyntaxError(message, fn, ln, cn)
846 continue 848 continue
847 849
848 if resp == ResponseExit: 850 if resp == ResponseExit:
849 self.debugServer.signalClientExit(line[eoc:-1]) 851 self.debugServer.signalClientExit(evalArg)
850 continue 852 continue
851 853
852 if resp == ResponseClearBreak: 854 if resp == ResponseClearBreak:
853 fn, lineno = line[eoc:-1].split(',') 855 fn, lineno = evalArg.split(',')
854 lineno = int(lineno) 856 lineno = int(lineno)
855 fn = self.translate(fn, True) 857 fn = self.translate(fn, True)
856 self.debugServer.signalClientClearBreak(fn, lineno) 858 self.debugServer.signalClientClearBreak(fn, lineno)
857 continue 859 continue
858 860
859 if resp == ResponseBPConditionError: 861 if resp == ResponseBPConditionError:
860 fn, lineno = line[eoc:-1].split(',') 862 fn, lineno = evalArg.split(',')
861 lineno = int(lineno) 863 lineno = int(lineno)
862 fn = self.translate(fn, True) 864 fn = self.translate(fn, True)
863 self.debugServer.signalClientBreakConditionError(fn, lineno) 865 self.debugServer.signalClientBreakConditionError(fn, lineno)
864 continue 866 continue
865 867
866 if resp == ResponseClearWatch: 868 if resp == ResponseClearWatch:
867 cond = line[eoc:-1] 869 self.debugServer.signalClientClearWatch(evalArg)
868 self.debugServer.signalClientClearWatch(cond)
869 continue 870 continue
870 871
871 if resp == ResponseWPConditionError: 872 if resp == ResponseWPConditionError:
872 cond = line[eoc:-1] 873 self.debugServer.signalClientWatchConditionError(evalArg)
873 self.debugServer.signalClientWatchConditionError(cond)
874 continue 874 continue
875 875
876 if resp == ResponseRaw: 876 if resp == ResponseRaw:
877 prompt, echo = eval(line[eoc:-1]) 877 prompt, echo = eval(evalArg)
878 self.debugServer.signalClientRawInput(prompt, echo) 878 self.debugServer.signalClientRawInput(prompt, echo)
879 continue 879 continue
880 880
881 if resp == ResponseBanner: 881 if resp == ResponseBanner:
882 version, platform, dbgclient = eval(line[eoc:-1]) 882 version, platform, dbgclient = eval(evalArg)
883 self.debugServer.signalClientBanner(version, platform, dbgclient) 883 self.debugServer.signalClientBanner(version, platform, dbgclient)
884 continue 884 continue
885 885
886 if resp == ResponseCapabilities: 886 if resp == ResponseCapabilities:
887 cap, clType = eval(line[eoc:-1]) 887 cap, clType = eval(evalArg)
888 self.clientCapabilities = cap 888 self.clientCapabilities = cap
889 self.debugServer.signalClientCapabilities(cap, clType) 889 self.debugServer.signalClientCapabilities(cap, clType)
890 continue 890 continue
891 891
892 if resp == ResponseCompletion: 892 if resp == ResponseCompletion:
893 clstring, text = line[eoc:-1].split('||') 893 clstring, text = evalArg.split('||')
894 cl = eval(clstring) 894 cl = eval(clstring)
895 self.debugServer.signalClientCompletionList(cl, text) 895 self.debugServer.signalClientCompletionList(cl, text)
896 continue 896 continue
897 897
898 if resp == PassiveStartup: 898 if resp == PassiveStartup:
899 fn, exc = line[eoc:-1].split('|') 899 fn, exc = evalArg.split('|')
900 exc = bool(exc) 900 exc = bool(exc)
901 fn = self.translate(fn, True) 901 fn = self.translate(fn, True)
902 self.debugServer.passiveStartUp(fn, exc) 902 self.debugServer.passiveStartUp(fn, exc)
903 continue 903 continue
904 904
905 if resp == ResponseUTPrepared: 905 if resp == ResponseUTPrepared:
906 res, exc_type, exc_value = eval(line[eoc:-1]) 906 res, exc_type, exc_value = eval(evalArg)
907 self.debugServer.clientUtPrepared(res, exc_type, exc_value) 907 self.debugServer.clientUtPrepared(res, exc_type, exc_value)
908 continue 908 continue
909 909
910 if resp == ResponseUTStartTest: 910 if resp == ResponseUTStartTest:
911 testname, doc = eval(line[eoc:-1]) 911 testname, doc = eval(evalArg)
912 self.debugServer.clientUtStartTest(testname, doc) 912 self.debugServer.clientUtStartTest(testname, doc)
913 continue 913 continue
914 914
915 if resp == ResponseUTStopTest: 915 if resp == ResponseUTStopTest:
916 self.debugServer.clientUtStopTest() 916 self.debugServer.clientUtStopTest()
917 continue 917 continue
918 918
919 if resp == ResponseUTTestFailed: 919 if resp == ResponseUTTestFailed:
920 testname, traceback = eval(line[eoc:-1]) 920 testname, traceback = eval(evalArg)
921 self.debugServer.clientUtTestFailed(testname, traceback) 921 self.debugServer.clientUtTestFailed(testname, traceback)
922 continue 922 continue
923 923
924 if resp == ResponseUTTestErrored: 924 if resp == ResponseUTTestErrored:
925 testname, traceback = eval(line[eoc:-1]) 925 testname, traceback = eval(evalArg)
926 self.debugServer.clientUtTestErrored(testname, traceback) 926 self.debugServer.clientUtTestErrored(testname, traceback)
927 continue 927 continue
928 928
929 if resp == ResponseUTFinished: 929 if resp == ResponseUTFinished:
930 self.debugServer.clientUtFinished() 930 self.debugServer.clientUtFinished()
931 continue 931 continue
932 932
933 if resp == RequestForkTo: 933 if resp == RequestForkTo:
934 self.__askForkTo() 934 self.__askForkTo()
935 continue 935 continue
936 936
937 self.debugServer.signalClientOutput(line) 937 self.debugServer.signalClientOutput(line)
938 938
939 def __sendCommand(self, cmd): 939 def __sendCommand(self, cmd):
940 """ 940 """
941 Private method to send a single line command to the client. 941 Private method to send a single line command to the client.

eric ide

mercurial