DebugClients/Python/DebugClientBase.py

changeset 1112
8a7d1b9d18db
parent 1029
0fb3d1d26eab
child 1179
7661ab683f7b
equal deleted inserted replaced
1109:9552b5e16a07 1112:8a7d1b9d18db
16 import time 16 import time
17 import imp 17 import imp
18 import re 18 import re
19 19
20 20
21 from DebugProtocol import * 21 import DebugProtocol
22 import DebugClientCapabilities 22 import DebugClientCapabilities
23 from DebugBase import setRecursionLimit, printerr # __IGNORE_WARNING__ 23 from DebugBase import setRecursionLimit, printerr # __IGNORE_WARNING__
24 from AsyncFile import * 24 from AsyncFile import AsyncFile, AsyncPendingWrite
25 from DebugConfig import ConfigVarTypeStrings 25 from DebugConfig import ConfigVarTypeStrings
26 from FlexCompleter import Completer 26 from FlexCompleter import Completer
27 27
28 28
29 DebugClientInstance = None 29 DebugClientInstance = None
204 204
205 # The list of regexp objects to filter variables against 205 # The list of regexp objects to filter variables against
206 self.globalsFilterObjects = [] 206 self.globalsFilterObjects = []
207 self.localsFilterObjects = [] 207 self.localsFilterObjects = []
208 208
209 self.pendingResponse = ResponseOK 209 self.pendingResponse = DebugProtocol.ResponseOK
210 self.fncache = {} 210 self.fncache = {}
211 self.dircache = [] 211 self.dircache = []
212 self.inRawMode = 0 212 self.inRawMode = 0
213 self.mainProcStr = None # used for the passive mode 213 self.mainProcStr = None # used for the passive mode
214 self.passive = 0 # used to indicate the passive mode 214 self.passive = 0 # used to indicate the passive mode
316 d["id"] = -1 316 d["id"] = -1
317 d["name"] = "MainThread" 317 d["name"] = "MainThread"
318 d["broken"] = self.isBroken() 318 d["broken"] = self.isBroken()
319 threadList.append(d) 319 threadList.append(d)
320 320
321 self.write('%s%s\n' % (ResponseThreadList, unicode((currentId, threadList)))) 321 self.write('%s%s\n' % (DebugProtocol.ResponseThreadList,
322 unicode((currentId, threadList))))
322 323
323 def raw_input(self, prompt, echo): 324 def raw_input(self, prompt, echo):
324 """ 325 """
325 Public method to implement raw_input() using the event loop. 326 Public method to implement raw_input() using the event loop.
326 327
327 @param prompt the prompt to be shown (string) 328 @param prompt the prompt to be shown (string)
328 @param echo Flag indicating echoing of the input (boolean) 329 @param echo Flag indicating echoing of the input (boolean)
329 @return the entered string 330 @return the entered string
330 """ 331 """
331 self.write("%s%s\n" % (ResponseRaw, unicode((prompt, echo)))) 332 self.write("%s%s\n" % (DebugProtocol.ResponseRaw, unicode((prompt, echo))))
332 self.inRawMode = 1 333 self.inRawMode = 1
333 self.eventLoop(True) 334 self.eventLoop(True)
334 return self.rawLine 335 return self.rawLine
335 336
336 def input(self, prompt): 337 def input(self, prompt):
346 """ 347 """
347 Private method called in the case of an exception 348 Private method called in the case of an exception
348 349
349 It ensures that the debug server is informed of the raised exception. 350 It ensures that the debug server is informed of the raised exception.
350 """ 351 """
351 self.pendingResponse = ResponseException 352 self.pendingResponse = DebugProtocol.ResponseException
352 353
353 def sessionClose(self, exit=1): 354 def sessionClose(self, exit=1):
354 """ 355 """
355 Public method to close the session with the debugger and optionally terminate. 356 Public method to close the session with the debugger and optionally terminate.
356 357
396 if eoc >= 0 and line[0] == '>': 397 if eoc >= 0 and line[0] == '>':
397 # Get the command part and any argument. 398 # Get the command part and any argument.
398 cmd = line[:eoc + 1] 399 cmd = line[:eoc + 1]
399 arg = line[eoc + 1:] 400 arg = line[eoc + 1:]
400 401
401 if cmd == RequestVariables: 402 if cmd == DebugProtocol.RequestVariables:
402 frmnr, scope, filter = eval(arg) 403 frmnr, scope, filter = eval(arg)
403 self.__dumpVariables(int(frmnr), int(scope), filter) 404 self.__dumpVariables(int(frmnr), int(scope), filter)
404 return 405 return
405 406
406 if cmd == RequestVariable: 407 if cmd == DebugProtocol.RequestVariable:
407 var, frmnr, scope, filter = eval(arg) 408 var, frmnr, scope, filter = eval(arg)
408 self.__dumpVariable(var, int(frmnr), int(scope), filter) 409 self.__dumpVariable(var, int(frmnr), int(scope), filter)
409 return 410 return
410 411
411 if cmd == RequestThreadList: 412 if cmd == DebugProtocol.RequestThreadList:
412 self.__dumpThreadList() 413 self.__dumpThreadList()
413 return 414 return
414 415
415 if cmd == RequestThreadSet: 416 if cmd == DebugProtocol.RequestThreadSet:
416 tid = eval(arg) 417 tid = eval(arg)
417 if tid in self.threads: 418 if tid in self.threads:
418 self.setCurrentThread(tid) 419 self.setCurrentThread(tid)
419 self.write(ResponseThreadSet + '\n') 420 self.write(DebugProtocol.ResponseThreadSet + '\n')
420 stack = self.currentThread.getStack() 421 stack = self.currentThread.getStack()
421 self.write('%s%s\n' % (ResponseStack, unicode(stack))) 422 self.write('%s%s\n' % (DebugProtocol.ResponseStack, unicode(stack)))
422 return 423 return
423 424
424 if cmd == RequestStep: 425 if cmd == DebugProtocol.RequestStep:
425 self.currentThread.step(1) 426 self.currentThread.step(1)
426 self.eventExit = 1 427 self.eventExit = 1
427 return 428 return
428 429
429 if cmd == RequestStepOver: 430 if cmd == DebugProtocol.RequestStepOver:
430 self.currentThread.step(0) 431 self.currentThread.step(0)
431 self.eventExit = 1 432 self.eventExit = 1
432 return 433 return
433 434
434 if cmd == RequestStepOut: 435 if cmd == DebugProtocol.RequestStepOut:
435 self.currentThread.stepOut() 436 self.currentThread.stepOut()
436 self.eventExit = 1 437 self.eventExit = 1
437 return 438 return
438 439
439 if cmd == RequestStepQuit: 440 if cmd == DebugProtocol.RequestStepQuit:
440 if self.passive: 441 if self.passive:
441 self.progTerminated(42) 442 self.progTerminated(42)
442 else: 443 else:
443 self.set_quit() 444 self.set_quit()
444 self.eventExit = 1 445 self.eventExit = 1
445 return 446 return
446 447
447 if cmd == RequestContinue: 448 if cmd == DebugProtocol.RequestContinue:
448 special = int(arg) 449 special = int(arg)
449 self.currentThread.go(special) 450 self.currentThread.go(special)
450 self.eventExit = 1 451 self.eventExit = 1
451 return 452 return
452 453
453 if cmd == RequestOK: 454 if cmd == DebugProtocol.RequestOK:
454 self.write(self.pendingResponse + '\n') 455 self.write(self.pendingResponse + '\n')
455 self.pendingResponse = ResponseOK 456 self.pendingResponse = DebugProtocol.ResponseOK
456 return 457 return
457 458
458 if cmd == RequestEnv: 459 if cmd == DebugProtocol.RequestEnv:
459 env = eval(arg) 460 env = eval(arg)
460 for key, value in env.items(): 461 for key, value in env.items():
461 if key.endswith("+"): 462 if key.endswith("+"):
462 if key[:-1] in os.environ: 463 if key[:-1] in os.environ:
463 os.environ[key[:-1]] += value 464 os.environ[key[:-1]] += value
465 os.environ[key[:-1]] = value 466 os.environ[key[:-1]] = value
466 else: 467 else:
467 os.environ[key] = value 468 os.environ[key] = value
468 return 469 return
469 470
470 if cmd == RequestLoad: 471 if cmd == DebugProtocol.RequestLoad:
471 self.fncache = {} 472 self.fncache = {}
472 self.dircache = [] 473 self.dircache = []
473 sys.argv = [] 474 sys.argv = []
474 wd, fn, args, tracePython = arg.split('|') 475 wd, fn, args, tracePython = arg.split('|')
475 self.__setCoding(fn) 476 self.__setCoding(fn)
508 res = self.mainThread.run('execfile(' + repr(self.running) + ')', 509 res = self.mainThread.run('execfile(' + repr(self.running) + ')',
509 self.debugMod.__dict__) 510 self.debugMod.__dict__)
510 self.progTerminated(res) 511 self.progTerminated(res)
511 return 512 return
512 513
513 if cmd == RequestRun: 514 if cmd == DebugProtocol.RequestRun:
514 sys.argv = [] 515 sys.argv = []
515 wd, fn, args = arg.split('|') 516 wd, fn, args = arg.split('|')
516 self.__setCoding(fn) 517 self.__setCoding(fn)
517 sys.argv.append(fn) 518 sys.argv.append(fn)
518 sys.argv.extend(eval(args)) 519 sys.argv.extend(eval(args))
540 sys.modules['__main__'] = self.debugMod 541 sys.modules['__main__'] = self.debugMod
541 execfile(sys.argv[0], self.debugMod.__dict__) 542 execfile(sys.argv[0], self.debugMod.__dict__)
542 self.writestream.flush() 543 self.writestream.flush()
543 return 544 return
544 545
545 if cmd == RequestCoverage: 546 if cmd == DebugProtocol.RequestCoverage:
546 from coverage import coverage 547 from coverage import coverage
547 sys.argv = [] 548 sys.argv = []
548 wd, fn, args, erase = arg.split('@@') 549 wd, fn, args, erase = arg.split('@@')
549 self.__setCoding(fn) 550 self.__setCoding(fn)
550 sys.argv.append(fn) 551 sys.argv.append(fn)
573 self.cover.stop() 574 self.cover.stop()
574 self.cover.save() 575 self.cover.save()
575 self.writestream.flush() 576 self.writestream.flush()
576 return 577 return
577 578
578 if cmd == RequestProfile: 579 if cmd == DebugProtocol.RequestProfile:
579 sys.setprofile(None) 580 sys.setprofile(None)
580 import PyProfile 581 import PyProfile
581 sys.argv = [] 582 sys.argv = []
582 wd, fn, args, erase = arg.split('|') 583 wd, fn, args, erase = arg.split('|')
583 self.__setCoding(fn) 584 self.__setCoding(fn)
603 self.prof.run('execfile(%r)' % sys.argv[0]) 604 self.prof.run('execfile(%r)' % sys.argv[0])
604 self.prof.save() 605 self.prof.save()
605 self.writestream.flush() 606 self.writestream.flush()
606 return 607 return
607 608
608 if cmd == RequestShutdown: 609 if cmd == DebugProtocol.RequestShutdown:
609 self.sessionClose() 610 self.sessionClose()
610 return 611 return
611 612
612 if cmd == RequestBreak: 613 if cmd == DebugProtocol.RequestBreak:
613 fn, line, temporary, set, cond = arg.split('@@') 614 fn, line, temporary, set, cond = arg.split('@@')
614 line = int(line) 615 line = int(line)
615 set = int(set) 616 set = int(set)
616 temporary = int(temporary) 617 temporary = int(temporary)
617 618
621 else: 622 else:
622 try: 623 try:
623 compile(cond, '<string>', 'eval') 624 compile(cond, '<string>', 'eval')
624 except SyntaxError: 625 except SyntaxError:
625 self.write('%s%s,%d\n' % \ 626 self.write('%s%s,%d\n' % \
626 (ResponseBPConditionError, fn, line)) 627 (DebugProtocol.ResponseBPConditionError, fn, line))
627 return 628 return
628 self.mainThread.set_break(fn, line, temporary, cond) 629 self.mainThread.set_break(fn, line, temporary, cond)
629 else: 630 else:
630 self.mainThread.clear_break(fn, line) 631 self.mainThread.clear_break(fn, line)
631 632
632 return 633 return
633 634
634 if cmd == RequestBreakEnable: 635 if cmd == DebugProtocol.RequestBreakEnable:
635 fn, line, enable = arg.split(',') 636 fn, line, enable = arg.split(',')
636 line = int(line) 637 line = int(line)
637 enable = int(enable) 638 enable = int(enable)
638 639
639 bp = self.mainThread.get_break(fn, line) 640 bp = self.mainThread.get_break(fn, line)
643 else: 644 else:
644 bp.disable() 645 bp.disable()
645 646
646 return 647 return
647 648
648 if cmd == RequestBreakIgnore: 649 if cmd == DebugProtocol.RequestBreakIgnore:
649 fn, line, count = arg.split(',') 650 fn, line, count = arg.split(',')
650 line = int(line) 651 line = int(line)
651 count = int(count) 652 count = int(count)
652 653
653 bp = self.mainThread.get_break(fn, line) 654 bp = self.mainThread.get_break(fn, line)
654 if bp is not None: 655 if bp is not None:
655 bp.ignore = count 656 bp.ignore = count
656 657
657 return 658 return
658 659
659 if cmd == RequestWatch: 660 if cmd == DebugProtocol.RequestWatch:
660 cond, temporary, set = arg.split('@@') 661 cond, temporary, set = arg.split('@@')
661 set = int(set) 662 set = int(set)
662 temporary = int(temporary) 663 temporary = int(temporary)
663 664
664 if set: 665 if set:
665 if not cond.endswith('??created??') and \ 666 if not cond.endswith('??created??') and \
666 not cond.endswith('??changed??'): 667 not cond.endswith('??changed??'):
667 try: 668 try:
668 compile(cond, '<string>', 'eval') 669 compile(cond, '<string>', 'eval')
669 except SyntaxError: 670 except SyntaxError:
670 self.write('%s%s\n' % (ResponseWPConditionError, cond)) 671 self.write('%s%s\n' % (
672 DebugProtocol.ResponseWPConditionError, cond))
671 return 673 return
672 self.mainThread.set_watch(cond, temporary) 674 self.mainThread.set_watch(cond, temporary)
673 else: 675 else:
674 self.mainThread.clear_watch(cond) 676 self.mainThread.clear_watch(cond)
675 677
676 return 678 return
677 679
678 if cmd == RequestWatchEnable: 680 if cmd == DebugProtocol.RequestWatchEnable:
679 cond, enable = arg.split(',') 681 cond, enable = arg.split(',')
680 enable = int(enable) 682 enable = int(enable)
681 683
682 bp = self.mainThread.get_watch(cond) 684 bp = self.mainThread.get_watch(cond)
683 if bp is not None: 685 if bp is not None:
686 else: 688 else:
687 bp.disable() 689 bp.disable()
688 690
689 return 691 return
690 692
691 if cmd == RequestWatchIgnore: 693 if cmd == DebugProtocol.RequestWatchIgnore:
692 cond, count = arg.split(',') 694 cond, count = arg.split(',')
693 count = int(count) 695 count = int(count)
694 696
695 bp = self.mainThread.get_watch(cond) 697 bp = self.mainThread.get_watch(cond)
696 if bp is not None: 698 if bp is not None:
697 bp.ignore = count 699 bp.ignore = count
698 700
699 return 701 return
700 702
701 if cmd == RequestEval: 703 if cmd == DebugProtocol.RequestEval:
702 try: 704 try:
703 value = eval(arg, self.currentThread.getCurrentFrame().f_globals, 705 value = eval(arg, self.currentThread.getCurrentFrame().f_globals,
704 self.currentThread.getCurrentFrameLocals()) 706 self.currentThread.getCurrentFrameLocals())
705 except: 707 except:
706 # Report the exception and the traceback 708 # Report the exception and the traceback
719 finally: 721 finally:
720 tblist = tb = None 722 tblist = tb = None
721 723
722 map(self.write, list) 724 map(self.write, list)
723 725
724 self.write(ResponseException + '\n') 726 self.write(DebugProtocol.ResponseException + '\n')
725 727
726 else: 728 else:
727 self.write(unicode(value) + '\n') 729 self.write(unicode(value) + '\n')
728 self.write(ResponseOK + '\n') 730 self.write(DebugProtocol.ResponseOK + '\n')
729 731
730 return 732 return
731 733
732 if cmd == RequestExec: 734 if cmd == DebugProtocol.RequestExec:
733 _globals = self.currentThread.getCurrentFrame().f_globals 735 _globals = self.currentThread.getCurrentFrame().f_globals
734 _locals = self.currentThread.getCurrentFrameLocals() 736 _locals = self.currentThread.getCurrentFrameLocals()
735 try: 737 try:
736 code = compile(arg + '\n', '<stdin>', 'single') 738 code = compile(arg + '\n', '<stdin>', 'single')
737 exec code in _globals, _locals 739 exec code in _globals, _locals
752 finally: 754 finally:
753 tblist = tb = None 755 tblist = tb = None
754 756
755 map(self.write, list) 757 map(self.write, list)
756 758
757 self.write(ResponseException + '\n') 759 self.write(DebugProtocol.ResponseException + '\n')
758 760
759 return 761 return
760 762
761 if cmd == RequestBanner: 763 if cmd == DebugProtocol.RequestBanner:
762 self.write('%s%s\n' % (ResponseBanner, 764 self.write('%s%s\n' % (DebugProtocol.ResponseBanner,
763 unicode(("Python %s" % sys.version, socket.gethostname(), 765 unicode(("Python %s" % sys.version, socket.gethostname(),
764 self.variant)))) 766 self.variant))))
765 return 767 return
766 768
767 if cmd == RequestCapabilities: 769 if cmd == DebugProtocol.RequestCapabilities:
768 self.write('%s%d, "Python"\n' % (ResponseCapabilities, 770 self.write('%s%d, "Python"\n' % (DebugProtocol.ResponseCapabilities,
769 self.__clientCapabilities())) 771 self.__clientCapabilities()))
770 return 772 return
771 773
772 if cmd == RequestCompletion: 774 if cmd == DebugProtocol.RequestCompletion:
773 self.__completionList(arg) 775 self.__completionList(arg)
774 return 776 return
775 777
776 if cmd == RequestSetFilter: 778 if cmd == DebugProtocol.RequestSetFilter:
777 scope, filterString = eval(arg) 779 scope, filterString = eval(arg)
778 self.__generateFilterObjects(int(scope), filterString) 780 self.__generateFilterObjects(int(scope), filterString)
779 return 781 return
780 782
781 if cmd == RequestUTPrepare: 783 if cmd == DebugProtocol.RequestUTPrepare:
782 fn, tn, tfn, cov, covname, erase = arg.split('|') 784 fn, tn, tfn, cov, covname, erase = arg.split('|')
783 sys.path.insert(0, os.path.dirname(os.path.abspath(fn))) 785 sys.path.insert(0, os.path.dirname(os.path.abspath(fn)))
784 os.chdir(sys.path[0]) 786 os.chdir(sys.path[0])
785 787
786 # set the system exception handling function to ensure, that 788 # set the system exception handling function to ensure, that
796 except AttributeError: 798 except AttributeError:
797 self.test = unittest.defaultTestLoader\ 799 self.test = unittest.defaultTestLoader\
798 .loadTestsFromModule(utModule) 800 .loadTestsFromModule(utModule)
799 except: 801 except:
800 exc_type, exc_value, exc_tb = sys.exc_info() 802 exc_type, exc_value, exc_tb = sys.exc_info()
801 self.write('%s%s\n' % (ResponseUTPrepared, 803 self.write('%s%s\n' % (DebugProtocol.ResponseUTPrepared,
802 unicode((0, str(exc_type), str(exc_value))))) 804 unicode((0, str(exc_type), str(exc_value)))))
803 self.__exceptionRaised() 805 self.__exceptionRaised()
804 return 806 return
805 807
806 # generate a coverage object 808 # generate a coverage object
812 if int(erase): 814 if int(erase):
813 self.cover.erase() 815 self.cover.erase()
814 else: 816 else:
815 self.cover = None 817 self.cover = None
816 818
817 self.write('%s%s\n' % (ResponseUTPrepared, 819 self.write('%s%s\n' % (DebugProtocol.ResponseUTPrepared,
818 unicode((self.test.countTestCases(), "", "")))) 820 unicode((self.test.countTestCases(), "", ""))))
819 return 821 return
820 822
821 if cmd == RequestUTRun: 823 if cmd == DebugProtocol.RequestUTRun:
822 from DCTestResult import DCTestResult 824 from DCTestResult import DCTestResult
823 self.testResult = DCTestResult(self) 825 self.testResult = DCTestResult(self)
824 if self.cover: 826 if self.cover:
825 self.cover.start() 827 self.cover.start()
826 self.test.run(self.testResult) 828 self.test.run(self.testResult)
827 if self.cover: 829 if self.cover:
828 self.cover.stop() 830 self.cover.stop()
829 self.cover.save() 831 self.cover.save()
830 self.write('%s\n' % ResponseUTFinished) 832 self.write('%s\n' % DebugProtocol.ResponseUTFinished)
831 return 833 return
832 834
833 if cmd == RequestUTStop: 835 if cmd == DebugProtocol.RequestUTStop:
834 self.testResult.stop() 836 self.testResult.stop()
835 return 837 return
836 838
837 if cmd == ResponseForkTo: 839 if cmd == DebugProtocol.ResponseForkTo:
838 # this results from a separate event loop 840 # this results from a separate event loop
839 self.fork_child = (arg == 'child') 841 self.fork_child = (arg == 'child')
840 self.eventExit = 1 842 self.eventExit = 1
841 return 843 return
842 844
843 if cmd == RequestForkMode: 845 if cmd == DebugProtocol.RequestForkMode:
844 self.fork_auto, self.fork_child = eval(arg) 846 self.fork_auto, self.fork_child = eval(arg)
845 return 847 return
846 848
847 # If we are handling raw mode input then reset the mode and break out 849 # If we are handling raw mode input then reset the mode and break out
848 # of the current event loop. 850 # of the current event loop.
866 self.buffer = '' 868 self.buffer = ''
867 869
868 self.__exceptionRaised() 870 self.__exceptionRaised()
869 else: 871 else:
870 if code is None: 872 if code is None:
871 self.pendingResponse = ResponseContinue 873 self.pendingResponse = DebugProtocol.ResponseContinue
872 else: 874 else:
873 self.buffer = '' 875 self.buffer = ''
874 876
875 try: 877 try:
876 if self.running is None: 878 if self.running is None:
1056 @param remoteAddress the network address of the debug server host (string) 1058 @param remoteAddress the network address of the debug server host (string)
1057 @param redirect flag indicating redirection of stdin, stdout and stderr (boolean) 1059 @param redirect flag indicating redirection of stdin, stdout and stderr (boolean)
1058 """ 1060 """
1059 if remoteAddress is None: # default: 127.0.0.1 1061 if remoteAddress is None: # default: 127.0.0.1
1060 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 1062 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1061 sock.connect((DebugAddress, port)) 1063 sock.connect((DebugProtocol.DebugAddress, port))
1062 elif ":" in remoteAddress: # IPv6 1064 elif ":" in remoteAddress: # IPv6
1063 sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) 1065 sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
1064 sock.connect((remoteAddress, port)) 1066 sock.connect((remoteAddress, port))
1065 else: # IPv4 1067 else: # IPv4
1066 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 1068 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1169 status = 1 1171 status = 1
1170 1172
1171 if self.running: 1173 if self.running:
1172 self.set_quit() 1174 self.set_quit()
1173 self.running = None 1175 self.running = None
1174 self.write('%s%d\n' % (ResponseExit, status)) 1176 self.write('%s%d\n' % (DebugProtocol.ResponseExit, status))
1175 1177
1176 # reset coding 1178 # reset coding
1177 self.__coding = self.defaultCoding 1179 self.__coding = self.defaultCoding
1178 1180
1179 def __dumpVariables(self, frmnr, scope, filter): 1181 def __dumpVariables(self, frmnr, scope, filter):
1210 keylist = dict.keys() 1212 keylist = dict.keys()
1211 1213
1212 vlist = self.__formatVariablesList(keylist, dict, scope, filter) 1214 vlist = self.__formatVariablesList(keylist, dict, scope, filter)
1213 varlist.extend(vlist) 1215 varlist.extend(vlist)
1214 1216
1215 self.write('%s%s\n' % (ResponseVariables, unicode(varlist))) 1217 self.write('%s%s\n' % (DebugProtocol.ResponseVariables, unicode(varlist)))
1216 1218
1217 def __dumpVariable(self, var, frmnr, scope, filter): 1219 def __dumpVariable(self, var, frmnr, scope, filter):
1218 """ 1220 """
1219 Private method to return the variables of a frame to the debug server. 1221 Private method to return the variables of a frame to the debug server.
1220 1222
1315 oaccess = access 1317 oaccess = access
1316 else: 1318 else:
1317 oaccess = '' 1319 oaccess = ''
1318 try: 1320 try:
1319 exec 'mdict = dict%s.__dict__' % access 1321 exec 'mdict = dict%s.__dict__' % access
1320 ndict.update(mdict) 1322 ndict.update(mdict) # __IGNORE_WARNING__
1321 exec 'obj = dict%s' % access 1323 exec 'obj = dict%s' % access
1322 if mdict and not "sipThis" in mdict.keys(): 1324 if mdict and not "sipThis" in mdict.keys(): # __IGNORE_WARNING__
1323 del rvar[0:2] 1325 del rvar[0:2]
1324 access = "" 1326 access = ""
1325 except: 1327 except:
1326 pass 1328 pass
1327 try: 1329 try:
1328 cdict = {} 1330 cdict = {}
1329 exec 'slv = dict%s.__slots__' % access 1331 exec 'slv = dict%s.__slots__' % access
1330 for v in slv: 1332 for v in slv: # __IGNORE_WARNING__
1331 try: 1333 try:
1332 exec 'cdict[v] = dict%s.%s' % (access, v) 1334 exec 'cdict[v] = dict%s.%s' % (access, v)
1333 except: 1335 except:
1334 pass 1336 pass
1335 ndict.update(cdict) 1337 ndict.update(cdict)
1398 elif unicode(repr(obj)).startswith('['): 1400 elif unicode(repr(obj)).startswith('['):
1399 varlist.append(('...', 'list', "%d" % len(obj))) 1401 varlist.append(('...', 'list', "%d" % len(obj)))
1400 elif unicode(repr(obj)).startswith('('): 1402 elif unicode(repr(obj)).startswith('('):
1401 varlist.append(('...', 'tuple', "%d" % len(obj))) 1403 varlist.append(('...', 'tuple', "%d" % len(obj)))
1402 1404
1403 self.write('%s%s\n' % (ResponseVariable, unicode(varlist))) 1405 self.write('%s%s\n' % (DebugProtocol.ResponseVariable, unicode(varlist)))
1404 1406
1405 def __formatQt4Variable(self, value, vtype): 1407 def __formatQt4Variable(self, value, vtype):
1406 """ 1408 """
1407 Private method to produce a formated output of a simple Qt4 type. 1409 Private method to produce a formated output of a simple Qt4 type.
1408 1410
1658 try: 1660 try:
1659 comp = self.complete(text, state) 1661 comp = self.complete(text, state)
1660 except: 1662 except:
1661 comp = None 1663 comp = None
1662 1664
1663 self.write("%s%s||%s\n" % (ResponseCompletion, unicode(completions), text)) 1665 self.write("%s%s||%s\n" % (DebugProtocol.ResponseCompletion,
1666 unicode(completions), text))
1664 1667
1665 def startDebugger(self, filename=None, host=None, port=None, 1668 def startDebugger(self, filename=None, host=None, port=None,
1666 enableTrace=1, exceptions=1, tracePython=0, redirect=1): 1669 enableTrace=1, exceptions=1, tracePython=0, redirect=1):
1667 """ 1670 """
1668 Public method used to start the remote debugger. 1671 Public method used to start the remote debugger.
1691 except IndexError: 1694 except IndexError:
1692 self.running = None 1695 self.running = None
1693 if self.running: 1696 if self.running:
1694 self.__setCoding(self.running) 1697 self.__setCoding(self.running)
1695 self.passive = 1 1698 self.passive = 1
1696 self.write("%s%s|%d\n" % (PassiveStartup, self.running, exceptions)) 1699 self.write("%s%s|%d\n" % (DebugProtocol.PassiveStartup, self.running, exceptions))
1697 self.__interact() 1700 self.__interact()
1698 1701
1699 # setup the debugger variables 1702 # setup the debugger variables
1700 self.fncache = {} 1703 self.fncache = {}
1701 self.dircache = [] 1704 self.dircache = []
1750 self.mainFrame = None 1753 self.mainFrame = None
1751 self.inRawMode = 0 1754 self.inRawMode = 0
1752 self.debugging = 1 1755 self.debugging = 1
1753 1756
1754 self.passive = 1 1757 self.passive = 1
1755 self.write("%s%s|%d\n" % (PassiveStartup, self.running, exceptions)) 1758 self.write("%s%s|%d\n" % (DebugProtocol.PassiveStartup, self.running, exceptions))
1756 self.__interact() 1759 self.__interact()
1757 1760
1758 self.attachThread(mainThread=1) 1761 self.attachThread(mainThread=1)
1759 self.mainThread.tracePython = tracePython 1762 self.mainThread.tracePython = tracePython
1760 1763
1900 def fork(self): 1903 def fork(self):
1901 """ 1904 """
1902 Public method implementing a fork routine deciding which branch to follow. 1905 Public method implementing a fork routine deciding which branch to follow.
1903 """ 1906 """
1904 if not self.fork_auto: 1907 if not self.fork_auto:
1905 self.write(RequestForkTo + '\n') 1908 self.write(DebugProtocol.RequestForkTo + '\n')
1906 self.eventLoop(True) 1909 self.eventLoop(True)
1907 pid = DebugClientOrigFork() 1910 pid = DebugClientOrigFork()
1908 if pid == 0: 1911 if pid == 0:
1909 # child 1912 # child
1910 if not self.fork_child: 1913 if not self.fork_child:

eric ide

mercurial