Debugger/DebuggerInterfacePython.py

changeset 406
eacf81fad150
parent 112
16893e193e9d
child 465
c20e25deb33a
equal deleted inserted replaced
405:374066392929 406:eacf81fad150
36 exts = [] 36 exts = []
37 for ext in Preferences.getDebugger("PythonExtensions").split(): 37 for ext in Preferences.getDebugger("PythonExtensions").split():
38 if ext.startswith("."): 38 if ext.startswith("."):
39 exts.append(ext) 39 exts.append(ext)
40 else: 40 else:
41 exts.append(".%s" % ext) 41 exts.append(".{0}".format(ext))
42 42
43 if exts and Preferences.getDebugger("PythonInterpreter"): 43 if exts and Preferences.getDebugger("PythonInterpreter"):
44 return ["Python", ClientDefaultCapabilities, exts] 44 return ["Python", ClientDefaultCapabilities, exts]
45 else: 45 else:
46 return ["", 0, []] 46 return ["", 0, []]
119 """ 119 """
120 proc = QProcess() 120 proc = QProcess()
121 if environment is not None: 121 if environment is not None:
122 env = [] 122 env = []
123 for key, value in list(environment.items()): 123 for key, value in list(environment.items()):
124 env.append("%s=%s" % (key, value)) 124 env.append("{0}={1}".format(key, value))
125 proc.setEnvironment(env) 125 proc.setEnvironment(env)
126 args = [] 126 args = []
127 for arg in arguments: 127 for arg in arguments:
128 args.append(arg) 128 args.append(arg)
129 proc.start(program, args) 129 proc.start(program, args)
386 self.disconnect(self.qsock, SIGNAL('disconnected()'), 386 self.disconnect(self.qsock, SIGNAL('disconnected()'),
387 self.debugServer.startClient) 387 self.debugServer.startClient)
388 self.disconnect(self.qsock, SIGNAL('readyRead()'), self.__parseClientLine) 388 self.disconnect(self.qsock, SIGNAL('readyRead()'), self.__parseClientLine)
389 389
390 # close down socket, and shut down client as well. 390 # close down socket, and shut down client as well.
391 self.__sendCommand('%s\n' % RequestShutdown) 391 self.__sendCommand('{0}\n'.format(RequestShutdown))
392 self.qsock.flush() 392 self.qsock.flush()
393 393
394 self.qsock.close() 394 self.qsock.close()
395 395
396 # reinitialize 396 # reinitialize
409 """ 409 """
410 Public method to set the environment for a program to debug, run, ... 410 Public method to set the environment for a program to debug, run, ...
411 411
412 @param env environment settings (dictionary) 412 @param env environment settings (dictionary)
413 """ 413 """
414 self.__sendCommand('%s%s\n' % (RequestEnv, str(env))) 414 self.__sendCommand('{0}{1}\n'.format(RequestEnv, str(env)))
415 415
416 def remoteLoad(self, fn, argv, wd, traceInterpreter = False, autoContinue = True, 416 def remoteLoad(self, fn, argv, wd, traceInterpreter = False, autoContinue = True,
417 autoFork = False, forkChild = False): 417 autoFork = False, forkChild = False):
418 """ 418 """
419 Public method to load a new program to debug. 419 Public method to load a new program to debug.
430 """ 430 """
431 self.__autoContinue = autoContinue 431 self.__autoContinue = autoContinue
432 432
433 wd = self.translate(wd, False) 433 wd = self.translate(wd, False)
434 fn = self.translate(os.path.abspath(fn), False) 434 fn = self.translate(os.path.abspath(fn), False)
435 self.__sendCommand('%s%s\n' % (RequestForkMode, repr((autoFork, forkChild)))) 435 self.__sendCommand('{0}{1}\n'.format(RequestForkMode, repr((autoFork, forkChild))))
436 self.__sendCommand('%s%s|%s|%s|%d\n' % \ 436 self.__sendCommand('{0}{1}|{2}|{3}|{4:d}\n'.format(
437 (RequestLoad, wd, fn, str(Utilities.parseOptionString(argv)), 437 RequestLoad, wd, fn, str(Utilities.parseOptionString(argv)),
438 traceInterpreter)) 438 traceInterpreter))
439 439
440 def remoteRun(self, fn, argv, wd, autoFork = False, forkChild = False): 440 def remoteRun(self, fn, argv, wd, autoFork = False, forkChild = False):
441 """ 441 """
442 Public method to load a new program to run. 442 Public method to load a new program to run.
447 @keyparam autoFork flag indicating the automatic fork mode (boolean) 447 @keyparam autoFork flag indicating the automatic fork mode (boolean)
448 @keyparam forkChild flag indicating to debug the child after forking (boolean) 448 @keyparam forkChild flag indicating to debug the child after forking (boolean)
449 """ 449 """
450 wd = self.translate(wd, False) 450 wd = self.translate(wd, False)
451 fn = self.translate(os.path.abspath(fn), False) 451 fn = self.translate(os.path.abspath(fn), False)
452 self.__sendCommand('%s%s\n' % (RequestForkMode, repr((autoFork, forkChild)))) 452 self.__sendCommand('{0}{1}\n'.format(RequestForkMode, repr((autoFork, forkChild))))
453 self.__sendCommand('%s%s|%s|%s\n' % \ 453 self.__sendCommand('{0}{1}|{2}|{3}\n'.format(
454 (RequestRun, wd, fn, str(Utilities.parseOptionString(argv)))) 454 RequestRun, wd, fn, str(Utilities.parseOptionString(argv))))
455 455
456 def remoteCoverage(self, fn, argv, wd, erase = False): 456 def remoteCoverage(self, fn, argv, wd, erase = False):
457 """ 457 """
458 Public method to load a new program to collect coverage data. 458 Public method to load a new program to collect coverage data.
459 459
463 @keyparam erase flag indicating that coverage info should be 463 @keyparam erase flag indicating that coverage info should be
464 cleared first (boolean) 464 cleared first (boolean)
465 """ 465 """
466 wd = self.translate(wd, False) 466 wd = self.translate(wd, False)
467 fn = self.translate(os.path.abspath(fn), False) 467 fn = self.translate(os.path.abspath(fn), False)
468 self.__sendCommand('%s%s@@%s@@%s@@%d\n' % \ 468 self.__sendCommand('{0}{1}@@{2}@@{3}@@{4:d}\n'.format(
469 (RequestCoverage, wd, fn, str(Utilities.parseOptionString(argv)), 469 RequestCoverage, wd, fn, str(Utilities.parseOptionString(argv)),
470 erase)) 470 erase))
471 471
472 def remoteProfile(self, fn, argv, wd, erase = False): 472 def remoteProfile(self, fn, argv, wd, erase = False):
473 """ 473 """
474 Public method to load a new program to collect profiling data. 474 Public method to load a new program to collect profiling data.
478 @param wd the working directory for the program (string) 478 @param wd the working directory for the program (string)
479 @keyparam erase flag indicating that timing info should be cleared first (boolean) 479 @keyparam erase flag indicating that timing info should be cleared first (boolean)
480 """ 480 """
481 wd = self.translate(wd, False) 481 wd = self.translate(wd, False)
482 fn = self.translate(os.path.abspath(fn), False) 482 fn = self.translate(os.path.abspath(fn), False)
483 self.__sendCommand('%s%s|%s|%s|%d\n' % \ 483 self.__sendCommand('{0}{1}|{2}|{3}|{4:d}\n'.format(
484 (RequestProfile, wd, fn, str(Utilities.parseOptionString(argv)), erase)) 484 RequestProfile, wd, fn, str(Utilities.parseOptionString(argv)), erase))
485 485
486 def remoteStatement(self, stmt): 486 def remoteStatement(self, stmt):
487 """ 487 """
488 Public method to execute a Python statement. 488 Public method to execute a Python statement.
489 489
490 @param stmt the Python statement to execute (string). It 490 @param stmt the Python statement to execute (string). It
491 should not have a trailing newline. 491 should not have a trailing newline.
492 """ 492 """
493 self.__sendCommand('%s\n' % stmt) 493 self.__sendCommand('{0}\n'.format(stmt))
494 self.__sendCommand(RequestOK + '\n') 494 self.__sendCommand(RequestOK + '\n')
495 495
496 def remoteStep(self): 496 def remoteStep(self):
497 """ 497 """
498 Public method to single step the debugged program. 498 Public method to single step the debugged program.
521 """ 521 """
522 Public method to continue the debugged program. 522 Public method to continue the debugged program.
523 523
524 @param special flag indicating a special continue operation (boolean) 524 @param special flag indicating a special continue operation (boolean)
525 """ 525 """
526 self.__sendCommand('%s%d\n' % (RequestContinue, special)) 526 self.__sendCommand('{0}{1:d}\n'.format(RequestContinue, special))
527 527
528 def remoteBreakpoint(self, fn, line, set, cond = None, temp = False): 528 def remoteBreakpoint(self, fn, line, set, cond = None, temp = False):
529 """ 529 """
530 Public method to set or clear a breakpoint. 530 Public method to set or clear a breakpoint.
531 531
534 @param set flag indicating setting or resetting a breakpoint (boolean) 534 @param set flag indicating setting or resetting a breakpoint (boolean)
535 @param cond condition of the breakpoint (string) 535 @param cond condition of the breakpoint (string)
536 @param temp flag indicating a temporary breakpoint (boolean) 536 @param temp flag indicating a temporary breakpoint (boolean)
537 """ 537 """
538 fn = self.translate(fn, False) 538 fn = self.translate(fn, False)
539 self.__sendCommand('%s%s@@%d@@%d@@%d@@%s\n' % \ 539 self.__sendCommand('{0}{1}@@{2:d}@@{3:d}@@{4:d}@@{5}\n'.format(
540 (RequestBreak, fn, line, temp, set, cond)) 540 RequestBreak, fn, line, temp, set, cond))
541 541
542 def remoteBreakpointEnable(self, fn, line, enable): 542 def remoteBreakpointEnable(self, fn, line, enable):
543 """ 543 """
544 Public method to enable or disable a breakpoint. 544 Public method to enable or disable a breakpoint.
545 545
546 @param fn filename the breakpoint belongs to (string) 546 @param fn filename the breakpoint belongs to (string)
547 @param line linenumber of the breakpoint (int) 547 @param line linenumber of the breakpoint (int)
548 @param enable flag indicating enabling or disabling a breakpoint (boolean) 548 @param enable flag indicating enabling or disabling a breakpoint (boolean)
549 """ 549 """
550 fn = self.translate(fn, False) 550 fn = self.translate(fn, False)
551 self.__sendCommand('%s%s,%d,%d\n' % (RequestBreakEnable, fn, line, enable)) 551 self.__sendCommand('{0}{1},{2:d},{3:d}\n'.format(
552 RequestBreakEnable, fn, line, enable))
552 553
553 def remoteBreakpointIgnore(self, fn, line, count): 554 def remoteBreakpointIgnore(self, fn, line, count):
554 """ 555 """
555 Public method to ignore a breakpoint the next couple of occurrences. 556 Public method to ignore a breakpoint the next couple of occurrences.
556 557
557 @param fn filename the breakpoint belongs to (string) 558 @param fn filename the breakpoint belongs to (string)
558 @param line linenumber of the breakpoint (int) 559 @param line linenumber of the breakpoint (int)
559 @param count number of occurrences to ignore (int) 560 @param count number of occurrences to ignore (int)
560 """ 561 """
561 fn = self.translate(fn, False) 562 fn = self.translate(fn, False)
562 self.__sendCommand('%s%s,%d,%d\n' % (RequestBreakIgnore, fn, line, count)) 563 self.__sendCommand('{0}{1},{2:d},{3:d}\n'.format(
564 RequestBreakIgnore, fn, line, count))
563 565
564 def remoteWatchpoint(self, cond, set, temp = False): 566 def remoteWatchpoint(self, cond, set, temp = False):
565 """ 567 """
566 Public method to set or clear a watch expression. 568 Public method to set or clear a watch expression.
567 569
568 @param cond expression of the watch expression (string) 570 @param cond expression of the watch expression (string)
569 @param set flag indicating setting or resetting a watch expression (boolean) 571 @param set flag indicating setting or resetting a watch expression (boolean)
570 @param temp flag indicating a temporary watch expression (boolean) 572 @param temp flag indicating a temporary watch expression (boolean)
571 """ 573 """
572 # cond is combination of cond and special (s. watch expression viewer) 574 # cond is combination of cond and special (s. watch expression viewer)
573 self.__sendCommand('%s%s@@%d@@%d\n' % (RequestWatch, cond, temp, set)) 575 self.__sendCommand('{0}{1}@@{2:d}@@{3:d}\n'.format(RequestWatch, cond, temp, set))
574 576
575 def remoteWatchpointEnable(self, cond, enable): 577 def remoteWatchpointEnable(self, cond, enable):
576 """ 578 """
577 Public method to enable or disable a watch expression. 579 Public method to enable or disable a watch expression.
578 580
579 @param cond expression of the watch expression (string) 581 @param cond expression of the watch expression (string)
580 @param enable flag indicating enabling or disabling a watch expression (boolean) 582 @param enable flag indicating enabling or disabling a watch expression (boolean)
581 """ 583 """
582 # cond is combination of cond and special (s. watch expression viewer) 584 # cond is combination of cond and special (s. watch expression viewer)
583 self.__sendCommand('%s%s,%d\n' % (RequestWatchEnable, cond, enable)) 585 self.__sendCommand('{0}{1},{2:d}\n'.format(RequestWatchEnable, cond, enable))
584 586
585 def remoteWatchpointIgnore(self, cond, count): 587 def remoteWatchpointIgnore(self, cond, count):
586 """ 588 """
587 Public method to ignore a watch expression the next couple of occurrences. 589 Public method to ignore a watch expression the next couple of occurrences.
588 590
589 @param cond expression of the watch expression (string) 591 @param cond expression of the watch expression (string)
590 @param count number of occurrences to ignore (int) 592 @param count number of occurrences to ignore (int)
591 """ 593 """
592 # cond is combination of cond and special (s. watch expression viewer) 594 # cond is combination of cond and special (s. watch expression viewer)
593 self.__sendCommand('%s%s,%d\n' % (RequestWatchIgnore, cond, count)) 595 self.__sendCommand('{0}{1},{2:d}\n'.format(RequestWatchIgnore, cond, count))
594 596
595 def remoteRawInput(self,s): 597 def remoteRawInput(self,s):
596 """ 598 """
597 Public method to send the raw input to the debugged program. 599 Public method to send the raw input to the debugged program.
598 600
602 604
603 def remoteThreadList(self): 605 def remoteThreadList(self):
604 """ 606 """
605 Public method to request the list of threads from the client. 607 Public method to request the list of threads from the client.
606 """ 608 """
607 self.__sendCommand('%s\n' % RequestThreadList) 609 self.__sendCommand('{0}\n'.format(RequestThreadList))
608 610
609 def remoteSetThread(self, tid): 611 def remoteSetThread(self, tid):
610 """ 612 """
611 Public method to request to set the given thread as current thread. 613 Public method to request to set the given thread as current thread.
612 614
613 @param tid id of the thread (integer) 615 @param tid id of the thread (integer)
614 """ 616 """
615 self.__sendCommand('%s%d\n' % (RequestThreadSet, tid)) 617 self.__sendCommand('{0}{1:d}\n'.format(RequestThreadSet, tid))
616 618
617 def remoteClientVariables(self, scope, filter, framenr = 0): 619 def remoteClientVariables(self, scope, filter, framenr = 0):
618 """ 620 """
619 Public method to request the variables of the debugged program. 621 Public method to request the variables of the debugged program.
620 622
621 @param scope the scope of the variables (0 = local, 1 = global) 623 @param scope the scope of the variables (0 = local, 1 = global)
622 @param filter list of variable types to filter out (list of int) 624 @param filter list of variable types to filter out (list of int)
623 @param framenr framenumber of the variables to retrieve (int) 625 @param framenr framenumber of the variables to retrieve (int)
624 """ 626 """
625 self.__sendCommand('%s%d, %d, %s\n' % \ 627 self.__sendCommand('{0}{1:d}, {2:d}, {3}\n'.format(
626 (RequestVariables, framenr, scope, str(filter))) 628 RequestVariables, framenr, scope, str(filter)))
627 629
628 def remoteClientVariable(self, scope, filter, var, framenr = 0): 630 def remoteClientVariable(self, scope, filter, var, framenr = 0):
629 """ 631 """
630 Public method to request the variables of the debugged program. 632 Public method to request the variables of the debugged program.
631 633
632 @param scope the scope of the variables (0 = local, 1 = global) 634 @param scope the scope of the variables (0 = local, 1 = global)
633 @param filter list of variable types to filter out (list of int) 635 @param filter list of variable types to filter out (list of int)
634 @param var list encoded name of variable to retrieve (string) 636 @param var list encoded name of variable to retrieve (string)
635 @param framenr framenumber of the variables to retrieve (int) 637 @param framenr framenumber of the variables to retrieve (int)
636 """ 638 """
637 self.__sendCommand('%s%s, %d, %d, %s\n' % \ 639 self.__sendCommand('{0}{1}, {2:d}, {3:d}, {4}\n'.format(
638 (RequestVariable, str(var), framenr, scope, str(filter))) 640 RequestVariable, str(var), framenr, scope, str(filter)))
639 641
640 def remoteClientSetFilter(self, scope, filter): 642 def remoteClientSetFilter(self, scope, filter):
641 """ 643 """
642 Public method to set a variables filter list. 644 Public method to set a variables filter list.
643 645
644 @param scope the scope of the variables (0 = local, 1 = global) 646 @param scope the scope of the variables (0 = local, 1 = global)
645 @param filter regexp string for variable names to filter out (string) 647 @param filter regexp string for variable names to filter out (string)
646 """ 648 """
647 self.__sendCommand('%s%d, "%s"\n' % (RequestSetFilter, scope, filter)) 649 self.__sendCommand('{0}{1:d}, "{2}"\n'.format(RequestSetFilter, scope, filter))
648 650
649 def remoteEval(self, arg): 651 def remoteEval(self, arg):
650 """ 652 """
651 Public method to evaluate arg in the current context of the debugged program. 653 Public method to evaluate arg in the current context of the debugged program.
652 654
653 @param arg the arguments to evaluate (string) 655 @param arg the arguments to evaluate (string)
654 """ 656 """
655 self.__sendCommand('%s%s\n' % (RequestEval, arg)) 657 self.__sendCommand('{0}{1}\n'.format(RequestEval, arg))
656 658
657 def remoteExec(self, stmt): 659 def remoteExec(self, stmt):
658 """ 660 """
659 Public method to execute stmt in the current context of the debugged program. 661 Public method to execute stmt in the current context of the debugged program.
660 662
661 @param stmt statement to execute (string) 663 @param stmt statement to execute (string)
662 """ 664 """
663 self.__sendCommand('%s%s\n' % (RequestExec, stmt)) 665 self.__sendCommand('{0}{1}\n'.format(RequestExec, stmt))
664 666
665 def remoteBanner(self): 667 def remoteBanner(self):
666 """ 668 """
667 Public slot to get the banner info of the remote client. 669 Public slot to get the banner info of the remote client.
668 """ 670 """
679 Public slot to get the a list of possible commandline completions 681 Public slot to get the a list of possible commandline completions
680 from the remote client. 682 from the remote client.
681 683
682 @param text the text to be completed (string) 684 @param text the text to be completed (string)
683 """ 685 """
684 self.__sendCommand("%s%s\n" % (RequestCompletion, text)) 686 self.__sendCommand("{0}{1}\n".format(RequestCompletion, text))
685 687
686 def remoteUTPrepare(self, fn, tn, tfn, cov, covname, coverase): 688 def remoteUTPrepare(self, fn, tn, tfn, cov, covname, coverase):
687 """ 689 """
688 Public method to prepare a new unittest run. 690 Public method to prepare a new unittest run.
689 691
694 @param covname filename to be used to assemble the coverage caches 696 @param covname filename to be used to assemble the coverage caches
695 filename 697 filename
696 @param coverase flag indicating erasure of coverage data is requested 698 @param coverase flag indicating erasure of coverage data is requested
697 """ 699 """
698 fn = self.translate(os.path.abspath(fn), False) 700 fn = self.translate(os.path.abspath(fn), False)
699 self.__sendCommand('%s%s|%s|%s|%d|%s|%d\n' % \ 701 self.__sendCommand('{0}{1}|{2}|{3}|{4:d}|{5}|{6:d}\n'.format(
700 (RequestUTPrepare, fn, tn, tfn, cov, covname, coverase)) 702 RequestUTPrepare, fn, tn, tfn, cov, covname, coverase))
701 703
702 def remoteUTRun(self): 704 def remoteUTRun(self):
703 """ 705 """
704 Public method to start a unittest run. 706 Public method to start a unittest run.
705 """ 707 """
706 self.__sendCommand('%s\n' % RequestUTRun) 708 self.__sendCommand('{0}\n'.format(RequestUTRun))
707 709
708 def remoteUTStop(self): 710 def remoteUTStop(self):
709 """ 711 """
710 Public method to stop a unittest run. 712 Public method to stop a unittest run.
711 """ 713 """
712 self.__sendCommand('%s\n' % RequestUTStop) 714 self.__sendCommand('{0}\n'.format(RequestUTStop))
713 715
714 def __askForkTo(self): 716 def __askForkTo(self):
715 """ 717 """
716 Private method to ask the user which branch of a fork to follow. 718 Private method to ask the user which branch of a fork to follow.
717 """ 719 """

eric ide

mercurial