63 pathsToSkip = ('<', os.path.dirname(__file__), inspect.__file__[:-1]) |
63 pathsToSkip = ('<', os.path.dirname(__file__), inspect.__file__[:-1]) |
64 filesToSkip = {} |
64 filesToSkip = {} |
65 |
65 |
66 # cache for fixed file names |
66 # cache for fixed file names |
67 _fnCache = {} |
67 _fnCache = {} |
|
68 |
|
69 # Stop all timers, when greenlets are used |
|
70 pollTimerEnabled = True |
68 |
71 |
69 def __init__(self, dbgClient): |
72 def __init__(self, dbgClient): |
70 """ |
73 """ |
71 Constructor |
74 Constructor |
72 |
75 |
110 |
113 |
111 def __eventPollTimer(self): |
114 def __eventPollTimer(self): |
112 """ |
115 """ |
113 Private method to set a flag every 0.5 s to check for new messages. |
116 Private method to set a flag every 0.5 s to check for new messages. |
114 """ |
117 """ |
115 while True: |
118 while DebugBase.pollTimerEnabled: |
116 time.sleep(0.5) |
119 time.sleep(0.5) |
117 self.eventPollFlag = True |
120 self.eventPollFlag = True |
|
121 |
|
122 self.eventPollFlag = False |
118 |
123 |
119 def getCurrentFrame(self): |
124 def getCurrentFrame(self): |
120 """ |
125 """ |
121 Public method to return the current frame. |
126 Public method to return the current frame. |
122 |
127 |
355 if event == 'c_exception': |
360 if event == 'c_exception': |
356 return |
361 return |
357 if event == 'c_return': |
362 if event == 'c_return': |
358 return |
363 return |
359 |
364 |
360 print('DebugBase.trace_dispatch:' # __IGNORE_WARNING__ |
365 print('DebugBase.trace_dispatch:' # __IGNORE_WARNING_M801__ |
361 ' unknown debugging event: ', |
366 ' unknown debugging event: ', |
362 repr(event)) |
367 repr(event)) |
363 return self.trace_dispatch |
368 return self.trace_dispatch |
364 |
369 |
365 def set_trace(self, frame=None): |
370 def set_trace(self, frame=None): |
419 self.user_exception(excinfo, True) |
424 self.user_exception(excinfo, True) |
420 finally: |
425 finally: |
421 sys.settrace(None) |
426 sys.settrace(None) |
422 sys.setprofile(None) |
427 sys.setprofile(None) |
423 |
428 |
424 def run(self, cmd, globals=None, locals=None, debug=True): |
429 def run(self, cmd, globalsDict=None, localsDict=None, debug=True): |
425 """ |
430 """ |
426 Public method to start a given command under debugger control. |
431 Public method to start a given command under debugger control. |
427 |
432 |
428 @param cmd command / code to execute under debugger control |
433 @param cmd command / code to execute under debugger control |
429 @type str or CodeType |
434 @type str or CodeType |
430 @keyparam globals dictionary of global variables for cmd |
435 @keyparam globalsDict dictionary of global variables for cmd |
431 @type dict |
436 @type dict |
432 @keyparam locals dictionary of local variables for cmd |
437 @keyparam localsDict dictionary of local variables for cmd |
433 @type dict |
438 @type dict |
434 @keyparam debug flag if command should run under debugger control |
439 @keyparam debug flag if command should run under debugger control |
435 @type bool |
440 @type bool |
436 """ |
441 """ |
437 if globals is None: |
442 if globalsDict is None: |
438 import __main__ |
443 import __main__ |
439 globals = __main__.__dict__ |
444 globalsDict = __main__.__dict__ |
440 |
445 |
441 if locals is None: |
446 if localsDict is None: |
442 locals = globals |
447 localsDict = globalsDict |
443 |
448 |
444 if not isinstance(cmd, types.CodeType): |
449 if not isinstance(cmd, types.CodeType): |
445 cmd = compile(cmd, "<string>", "exec") |
450 cmd = compile(cmd, "<string>", "exec") |
446 |
451 |
447 if debug: |
452 if debug: |
450 # function call. This is ensured by setting stop_everywhere. |
455 # function call. This is ensured by setting stop_everywhere. |
451 self.stop_everywhere = True |
456 self.stop_everywhere = True |
452 sys.settrace(self.trace_dispatch) |
457 sys.settrace(self.trace_dispatch) |
453 |
458 |
454 try: |
459 try: |
455 exec(cmd, globals, locals) |
460 exec(cmd, globalsDict, localsDict) |
456 atexit._run_exitfuncs() |
461 atexit._run_exitfuncs() |
457 self._dbgClient.progTerminated(0) |
462 self._dbgClient.progTerminated(0) |
458 except SystemExit: |
463 except SystemExit: |
459 atexit._run_exitfuncs() |
464 atexit._run_exitfuncs() |
460 excinfo = sys.exc_info() |
465 excinfo = sys.exc_info() |
522 |
527 |
523 @param frame the frame object |
528 @param frame the frame object |
524 @type frame object |
529 @type frame object |
525 """ |
530 """ |
526 self._set_stopinfo(None, frame.f_back) |
531 self._set_stopinfo(None, frame.f_back) |
|
532 |
|
533 def move_instruction_pointer(self, lineno): |
|
534 """ |
|
535 Public methode to move the instruction pointer to another line. |
|
536 |
|
537 @param lineno new line number |
|
538 @type int |
|
539 """ |
|
540 try: |
|
541 self.currentFrame.f_lineno = lineno |
|
542 stack = self.getStack(self.currentFrame) |
|
543 self._dbgClient.sendResponseLine(stack) |
|
544 except Exception as e: |
|
545 printerr(e) |
527 |
546 |
528 def set_quit(self): |
547 def set_quit(self): |
529 """ |
548 """ |
530 Public method to quit. |
549 Public method to quit. |
531 |
550 |
560 # get module name from __file__ |
579 # get module name from __file__ |
561 fn = frame.f_globals.get('__file__') |
580 fn = frame.f_globals.get('__file__') |
562 try: |
581 try: |
563 return self._fnCache[fn] |
582 return self._fnCache[fn] |
564 except KeyError: |
583 except KeyError: |
565 if fn and fn != frame.f_code.co_filename: |
584 absFilename = os.path.abspath(fn) |
566 absFilename = os.path.abspath(fn) |
585 if absFilename.endswith(('.pyc', '.pyo')): |
567 if absFilename.endswith(('.pyc', '.pyo')): |
586 fixedName = absFilename[:-1] |
568 fixedName = absFilename[:-1] |
587 if not os.path.exists(fixedName): |
569 if not os.path.exists(fixedName): |
|
570 fixedName = absFilename |
|
571 else: |
|
572 fixedName = absFilename |
588 fixedName = absFilename |
573 else: |
589 else: |
574 fixedName = frame.f_code.co_filename |
590 fixedName = absFilename |
575 # update cache |
591 # update cache |
576 self._fnCache[fn] = fixedName |
592 self._fnCache[fn] = fixedName |
577 return fixedName |
593 return fixedName |
578 |
594 |
579 def __checkBreakInFrame(self, frame): |
595 def __checkBreakInFrame(self, frame): |
790 else: |
806 else: |
791 message = excval.msg |
807 message = excval.msg |
792 filename = excval.filename |
808 filename = excval.filename |
793 lineno = excval.lineno |
809 lineno = excval.lineno |
794 charno = excval.offset |
810 charno = excval.offset |
795 |
|
796 if charno is None: |
|
797 charno = 0 |
|
798 |
811 |
799 filename = os.path.abspath(filename) |
812 if filename is None: |
800 realSyntaxError = os.path.exists(filename) |
813 realSyntaxError = False |
|
814 else: |
|
815 if charno is None: |
|
816 charno = 0 |
|
817 |
|
818 filename = os.path.abspath(filename) |
|
819 realSyntaxError = os.path.exists(filename) |
|
820 |
801 except (AttributeError, ValueError): |
821 except (AttributeError, ValueError): |
802 message = "" |
822 message = "" |
803 filename = "" |
823 filename = "" |
804 lineno = 0 |
824 lineno = 0 |
805 charno = 0 |
825 charno = 0 |