def exception_break(plugin, pydb, pydb_frame, frame, args, arg): pydb = args[0] thread = args[3] exception, value, trace = arg if pydb.jinja2_exception_break and exception is not None: exception_type = dict_keys(pydb.jinja2_exception_break)[0] if exception.__name__ in ('UndefinedError', 'TemplateNotFound', 'TemplatesNotFound'): # errors in rendering render_frame = _find_jinja2_render_frame(frame) if render_frame: suspend_frame = _suspend_jinja2(pydb, thread, render_frame, CMD_ADD_EXCEPTION_BREAK, message=exception_type) if suspend_frame: add_exception_to_frame(suspend_frame, (exception, value, trace)) flag = True suspend_frame.f_back = frame frame = suspend_frame return flag, frame elif exception.__name__ in ('TemplateSyntaxError', 'TemplateAssertionError'): # errors in compile time name = frame.f_code.co_name if name in ('template', 'top-level template code', '<module>') or name.startswith('block '): # Jinja2 translates exception info and creates fake frame on his own pydb_frame.set_suspend(thread, CMD_ADD_EXCEPTION_BREAK) add_exception_to_frame(frame, (exception, value, trace)) thread.additional_info.suspend_type = JINJA2_SUSPEND thread.additional_info.pydev_message = str(exception_type) flag = True return flag, frame return None
def _excepthook(exctype, value, tb): from _pydevd_bundle.pydevd_frame import handle_breakpoint_condition, handle_breakpoint_expression global _handle_exceptions if _handle_exceptions: exception_breakpoint = get_exception_breakpoint(exctype, _handle_exceptions) else: exception_breakpoint = None #Always call the original excepthook before going on to call the debugger post mortem to show it. _original_excepthook(exctype, value, tb) if not exception_breakpoint: return if tb is None: #sometimes it can be None, e.g. with GTK return if exctype is KeyboardInterrupt: return frames = [] debugger = get_global_debugger() user_frame = None while tb: frame = tb.tb_frame if exception_breakpoint.ignore_libraries and not debugger.not_in_scope(frame.f_code.co_filename): user_frame = tb.tb_frame frames.append(tb.tb_frame) tb = tb.tb_next thread = threadingCurrentThread() frames_byid = dict([(id(frame),frame) for frame in frames]) if exception_breakpoint.ignore_libraries and user_frame is not None: frame = user_frame else: frame = frames[-1] exception = (exctype, value, tb) _set_additional_info_if_needed(thread) info = thread.additional_info add_exception_to_frame(frame, exception) if exception_breakpoint.condition is not None: eval_result = handle_breakpoint_condition(debugger, info, exception_breakpoint, frame) if not eval_result: return if exception_breakpoint.expression is not None: handle_breakpoint_expression(exception_breakpoint, info, frame) try: thread.additional_info.pydev_message = exception_breakpoint.qname except: thread.additional_info.pydev_message = exception_breakpoint.qname.encode('utf-8') pydevd_tracing.SetTrace(None) #no tracing from here pydev_log.debug('Handling post-mortem stop on exception breakpoint %s' % exception_breakpoint.qname) debugger.handle_post_mortem_stop(thread, frame, frames_byid, exception)
def exception_break(plugin, pydb, pydb_frame, frame, args, arg): pydb = args[0] thread = args[3] exception, value, trace = arg if pydb.jinja2_exception_break: exception_type = dict_keys(pydb.jinja2_exception_break)[0] if get_exception_name(exception) in ('UndefinedError', 'TemplateNotFound', 'TemplatesNotFound'): #errors in rendering render_frame = _find_jinja2_render_frame(frame) if render_frame: suspend_frame = _suspend_jinja2(pydb, thread, render_frame, CMD_ADD_EXCEPTION_BREAK, message=exception_type) if suspend_frame: add_exception_to_frame(suspend_frame, (exception, value, trace)) flag = True suspend_frame.f_back = frame frame = suspend_frame return flag, frame elif get_exception_name(exception) in ('TemplateSyntaxError', 'TemplateAssertionError'): #errors in compile time name = frame.f_code.co_name if name in ('template', 'top-level template code', '<module>') or name.startswith('block '): #Jinja2 translates exception info and creates fake frame on his own pydb_frame.set_suspend(thread, CMD_ADD_EXCEPTION_BREAK) add_exception_to_frame(frame, (exception, value, trace)) thread.additional_info.suspend_type = JINJA2_SUSPEND thread.additional_info.pydev_message = str(exception_type) flag = True return flag, frame return None
def stop_on_unhandled_exception(py_db, thread, additional_info, arg): exctype, value, tb = arg break_on_uncaught_exceptions = py_db.break_on_uncaught_exceptions if break_on_uncaught_exceptions: exception_breakpoint = py_db.get_exception_breakpoint( exctype, break_on_uncaught_exceptions) else: exception_breakpoint = None if not exception_breakpoint: return if tb is None: # sometimes it can be None, e.g. with GTK return if exctype is KeyboardInterrupt: return if py_db.exclude_exception_by_filter(exception_breakpoint, tb, True): return frames = [] user_frame = None while tb: frame = tb.tb_frame if exception_breakpoint.ignore_libraries and py_db.in_project_scope( frame.f_code.co_filename): user_frame = tb.tb_frame frames.append(tb.tb_frame) tb = tb.tb_next frames_byid = dict([(id(frame), frame) for frame in frames]) if exception_breakpoint.ignore_libraries and user_frame is not None: frame = user_frame else: frame = frames[-1] add_exception_to_frame(frame, arg) if exception_breakpoint.condition is not None: eval_result = py_db.handle_breakpoint_condition( additional_info, exception_breakpoint, frame) if not eval_result: return if exception_breakpoint.expression is not None: py_db.handle_breakpoint_expression(exception_breakpoint, additional_info, frame) try: additional_info.pydev_message = exception_breakpoint.qname except: additional_info.pydev_message = exception_breakpoint.qname.encode( 'utf-8') pydev_log.debug('Handling post-mortem stop on exception breakpoint %s' % (exception_breakpoint.qname, )) py_db.do_stop_on_unhandled_exception(thread, frame, frames_byid, arg)
def exception_break(plugin, main_debugger, pydb_frame, frame, args, arg): main_debugger = args[0] thread = args[3] exception, value, trace = arg if main_debugger.django_exception_break and exception is not None: if exception.__name__ in ['VariableDoesNotExist', 'TemplateDoesNotExist', 'TemplateSyntaxError'] and \ just_raised(trace) and not ignore_exception_trace(trace): if exception.__name__ == 'TemplateSyntaxError': # In this case we don't actually have a regular render frame with the context # (we didn't really get to that point). token = getattr(value, 'token', None) lineno = getattr(token, 'lineno', None) filename = None if lineno is not None: get_template_frame = frame while get_template_frame.f_code.co_name != 'get_template': get_template_frame = get_template_frame.f_back origin = None if get_template_frame is not None: origin = get_template_frame.f_locals.get('origin') if hasattr(origin, 'name') and origin.name is not None: filename = normcase(_convert_to_str(origin.name)) if filename is not None and lineno is not None: syntax_error_frame = DjangoTemplateSyntaxErrorFrame( frame, filename, lineno, { 'token': token, 'exception': exception }) suspend_frame = suspend_django(main_debugger, thread, syntax_error_frame, CMD_ADD_EXCEPTION_BREAK) return True, suspend_frame elif exception.__name__ == 'VariableDoesNotExist': if _is_django_variable_does_not_exist_exception_break_context( frame): render_frame = _find_django_render_frame(frame) if render_frame: suspend_frame = suspend_django( main_debugger, thread, DjangoTemplateFrame(render_frame), CMD_ADD_EXCEPTION_BREAK) if suspend_frame: add_exception_to_frame(suspend_frame, (exception, value, trace)) thread.additional_info.pydev_message = 'VariableDoesNotExist' suspend_frame.f_back = frame frame = suspend_frame return True, frame return None
def should_stop_on_exception(self, frame, event, arg): # ENDIF # main_debugger, _filename, info, _thread = self._args main_debugger = self._args[0] info = self._args[2] flag = False # STATE_SUSPEND = 2 if info.pydev_state != 2: #and breakpoint is not None: exception, value, trace = arg if trace is not None: #on jython trace is None on the first event exception_breakpoint = get_exception_breakpoint( exception, main_debugger.break_on_caught_exceptions) if exception_breakpoint is not None: if exception_breakpoint.ignore_libraries: if exception_breakpoint.notify_on_first_raise_only: if main_debugger.first_appearance_in_scope(trace): add_exception_to_frame( frame, (exception, value, trace)) try: info.pydev_message = exception_breakpoint.qname except: info.pydev_message = exception_breakpoint.qname.encode( 'utf-8') flag = True else: pydev_log.debug( "Ignore exception %s in library %s" % (exception, frame.f_code.co_filename)) flag = False else: if not exception_breakpoint.notify_on_first_raise_only or just_raised( trace): add_exception_to_frame(frame, (exception, value, trace)) try: info.pydev_message = exception_breakpoint.qname except: info.pydev_message = exception_breakpoint.qname.encode( 'utf-8') flag = True else: flag = False else: try: if main_debugger.plugin is not None: result = main_debugger.plugin.exception_break( main_debugger, self, frame, self._args, arg) if result: flag, frame = result except: flag = False return flag, frame
def stop_on_unhandled_exception(py_db, thread, additional_info, arg): from _pydevd_bundle.pydevd_frame import handle_breakpoint_condition, handle_breakpoint_expression exctype, value, tb = arg if exctype in (KeyboardInterrupt, SystemExit): return break_on_uncaught_exceptions = py_db.break_on_uncaught_exceptions if break_on_uncaught_exceptions: exception_breakpoint = get_exception_breakpoint(exctype, break_on_uncaught_exceptions) else: exception_breakpoint = None original_excepthook(exctype, value, tb) disable_excepthook() # Avoid printing the exception for the second time. if not exception_breakpoint: return if tb is None: # sometimes it can be None, e.g. with GTK return frames = [] user_frame = None while tb: frame = tb.tb_frame if exception_breakpoint.ignore_libraries and py_db.in_project_scope(frame.f_code.co_filename): user_frame = tb.tb_frame frames.append(tb.tb_frame) tb = tb.tb_next frames_byid = dict([(id(frame), frame) for frame in frames]) if exception_breakpoint.ignore_libraries and user_frame is not None: frame = user_frame else: frame = frames[-1] add_exception_to_frame(frame, arg) if exception_breakpoint.condition is not None: eval_result = handle_breakpoint_condition(py_db, additional_info, exception_breakpoint, frame) if not eval_result: return if exception_breakpoint.expression is not None: handle_breakpoint_expression(exception_breakpoint, additional_info, frame) try: additional_info.pydev_message = exception_breakpoint.qname except: additional_info.pydev_message = exception_breakpoint.qname.encode('utf-8') additional_info.pydev_message = 'python-%s' % additional_info.pydev_message pydev_log.debug('Handling post-mortem stop on exception breakpoint %s' % (exception_breakpoint.qname,)) py_db.stop_on_unhandled_exception(thread, frame, frames_byid, arg)
def exception_break(plugin, pydb, pydb_frame, frame, args, arg): if pydb.jupyter_exception_break and _is_inside_jupyter_cell(frame, pydb): thread = args[3] exception, value, trace = arg exception_type = dict_keys(pydb.jupyter_exception_break)[0] suspend_frame = suspend_jupyter(pydb, thread, frame, CMD_ADD_EXCEPTION_BREAK, message="jupyter-%s" % exception_type) if suspend_frame: add_exception_to_frame(suspend_frame, (exception, value, trace)) flag = True suspend_frame.f_back = frame return flag, suspend_frame return None
def exception_break(plugin, main_debugger, pydb_frame, frame, args, arg): main_debugger = args[0] thread = args[3] exception, value, trace = arg if main_debugger.django_exception_break and exception is not None: if exception.__name__ in ['VariableDoesNotExist', 'TemplateDoesNotExist', 'TemplateSyntaxError'] and \ just_raised(trace) and not ignore_exception_trace(trace): if exception.__name__ == 'TemplateSyntaxError': # In this case we don't actually have a regular render frame with the context # (we didn't really get to that point). token = getattr(value, 'token', None) if token is None: # Django 1.7 does not have token in exception. Try to get it from locals. token = frame.f_locals.get('token') lineno = getattr(token, 'lineno', None) filename = None if lineno is not None: filename = _get_filename_from_origin_in_parent_frame_locals(frame, 'get_template') if filename is None: # Django 1.7 does not have origin in get_template. Try to get it from # load_template. filename = _get_filename_from_origin_in_parent_frame_locals(frame, 'load_template') if filename is not None and lineno is not None: syntax_error_frame = DjangoTemplateSyntaxErrorFrame( frame, filename, lineno, {'token': token, 'exception': exception}) suspend_frame = suspend_django( main_debugger, thread, syntax_error_frame, CMD_ADD_EXCEPTION_BREAK) return True, suspend_frame elif exception.__name__ == 'VariableDoesNotExist': if _is_django_variable_does_not_exist_exception_break_context(frame): if not getattr(exception, 'silent_variable_failure', False) and not _is_ignoring_failures(frame): render_frame = _find_django_render_frame(frame) if render_frame: suspend_frame = suspend_django( main_debugger, thread, DjangoTemplateFrame(render_frame), CMD_ADD_EXCEPTION_BREAK) if suspend_frame: add_exception_to_frame(suspend_frame, (exception, value, trace)) thread.additional_info.pydev_message = 'VariableDoesNotExist' suspend_frame.f_back = frame frame = suspend_frame return True, frame return None
def stop_on_unhandled_exception(py_db, thread, additional_info, arg): exctype, value, tb = arg break_on_uncaught_exceptions = py_db.break_on_uncaught_exceptions if break_on_uncaught_exceptions: exception_breakpoint = py_db.get_exception_breakpoint(exctype, break_on_uncaught_exceptions) else: exception_breakpoint = None if not exception_breakpoint: return if tb is None: # sometimes it can be None, e.g. with GTK return if exctype is KeyboardInterrupt: return if py_db.exclude_exception_by_filter(exception_breakpoint, tb, True): return frames = [] user_frame = None while tb: frame = tb.tb_frame if exception_breakpoint.ignore_libraries and py_db.in_project_scope(frame.f_code.co_filename): user_frame = tb.tb_frame frames.append(tb.tb_frame) tb = tb.tb_next frames_byid = dict([(id(frame), frame) for frame in frames]) if exception_breakpoint.ignore_libraries and user_frame is not None: frame = user_frame else: frame = frames[-1] add_exception_to_frame(frame, arg) if exception_breakpoint.condition is not None: eval_result = py_db.handle_breakpoint_condition(additional_info, exception_breakpoint, frame) if not eval_result: return if exception_breakpoint.expression is not None: py_db.handle_breakpoint_expression(exception_breakpoint, additional_info, frame) try: additional_info.pydev_message = exception_breakpoint.qname except: additional_info.pydev_message = exception_breakpoint.qname.encode('utf-8') pydev_log.debug('Handling post-mortem stop on exception breakpoint %s' % (exception_breakpoint.qname,)) py_db.do_stop_on_unhandled_exception(thread, frame, frames_byid, arg)
def should_stop_on_exception(self, frame, event, arg): # ENDIF # main_debugger, _filename, info, _thread = self._args main_debugger = self._args[0] info = self._args[2] flag = False if info.pydev_state != STATE_SUSPEND: # and breakpoint is not None: exception, value, trace = arg if trace is not None: # on jython trace is None on the first event exception_breakpoint = get_exception_breakpoint(exception, main_debugger.break_on_caught_exceptions) if exception_breakpoint is not None: if exception_breakpoint.ignore_libraries: if exception_breakpoint.notify_on_first_raise_only: if main_debugger.first_appearance_in_scope(trace): add_exception_to_frame(frame, (exception, value, trace)) try: info.pydev_message = exception_breakpoint.qname except: info.pydev_message = exception_breakpoint.qname.encode("utf-8") flag = True else: pydev_log.debug( "Ignore exception %s in library %s" % (exception, frame.f_code.co_filename) ) flag = False else: if not exception_breakpoint.notify_on_first_raise_only or just_raised(trace): add_exception_to_frame(frame, (exception, value, trace)) try: info.pydev_message = exception_breakpoint.qname except: info.pydev_message = exception_breakpoint.qname.encode("utf-8") flag = True else: flag = False else: try: if main_debugger.plugin is not None: result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) if result: (flag, frame) = result except: flag = False return flag, frame
def exception_break(plugin, main_debugger, pydb_frame, frame, args, arg): main_debugger, filename, info, thread = args exception, value, trace = arg if main_debugger.django_exception_break and \ get_exception_name(exception) in ['VariableDoesNotExist', 'TemplateDoesNotExist', 'TemplateSyntaxError'] and \ just_raised(trace) and _is_django_exception_break_context(frame): render_frame = _find_django_render_frame(frame) if render_frame: suspend_frame = suspend_django(main_debugger, thread, render_frame, CMD_ADD_EXCEPTION_BREAK) if suspend_frame: add_exception_to_frame(suspend_frame, (exception, value, trace)) flag = True thread.additional_info.pydev_message = 'VariableDoesNotExist' suspend_frame.f_back = frame frame = suspend_frame return (flag, frame) return None
def exception_break(plugin, pydb, pydb_frame, frame, args, arg): pydb = args[0] thread = args[3] exception, value, trace = arg if pydb.jinja2_exception_break and exception is not None: exception_type = dict_keys(pydb.jinja2_exception_break)[0] if exception.__name__ in ('UndefinedError', 'TemplateNotFound', 'TemplatesNotFound'): # errors in rendering render_frame = _find_jinja2_render_frame(frame) if render_frame: suspend_frame = _suspend_jinja2(pydb, thread, render_frame, CMD_ADD_EXCEPTION_BREAK, message=exception_type) if suspend_frame: add_exception_to_frame(suspend_frame, (exception, value, trace)) suspend_frame.f_back = frame frame = suspend_frame return True, frame elif exception.__name__ in ('TemplateSyntaxError', 'TemplateAssertionError'): name = frame.f_code.co_name if IS_PY2: if name == 'fail': module_name = frame.f_globals.get('__name__', '') if module_name == 'jinja2.parser': filename = value.filename lineno = value.lineno syntax_error_frame = Jinja2TemplateSyntaxErrorFrame( frame, exception.__name__, filename, lineno, {'name': value.name, 'exception': value}) pydb_frame.set_suspend(thread, CMD_ADD_EXCEPTION_BREAK) add_exception_to_frame(syntax_error_frame, (exception, value, trace)) thread.additional_info.suspend_type = JINJA2_SUSPEND thread.additional_info.pydev_message = str(exception_type) return True, syntax_error_frame else: # errors in compile time if name in ('template', 'top-level template code', '<module>') or name.startswith('block '): f_back = frame.f_back if f_back is not None: module_name = f_back.f_globals.get('__name__', '') if module_name.startswith('jinja2.'): # Jinja2 translates exception info and creates fake frame on his own pydb_frame.set_suspend(thread, CMD_ADD_EXCEPTION_BREAK) add_exception_to_frame(frame, (exception, value, trace)) thread.additional_info.suspend_type = JINJA2_SUSPEND thread.additional_info.pydev_message = str(exception_type) return True, frame return None
def should_stop_on_exception(self, frame, event, arg): # ENDIF # main_debugger, _filename, info, _thread = self._args main_debugger = self._args[0] info = self._args[2] should_stop = False # STATE_SUSPEND = 2 if info.pydev_state != 2: # and breakpoint is not None: exception, value, trace = arg if trace is not None and hasattr(trace, 'tb_next'): # on jython trace is None on the first event and it may not have a tb_next. exception_breakpoint = main_debugger.get_exception_breakpoint( exception, main_debugger.break_on_caught_exceptions) if exception_breakpoint is not None: if exception_breakpoint.condition is not None: eval_result = main_debugger.handle_breakpoint_condition(info, exception_breakpoint, frame) if not eval_result: return False, frame if exception_breakpoint.ignore_libraries: if not main_debugger.is_exception_trace_in_project_scope(trace): pydev_log.debug("Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) return False, frame if ignore_exception_trace(trace): return False, frame was_just_raised = just_raised(trace) if was_just_raised: if main_debugger.skip_on_exceptions_thrown_in_same_context: # Option: Don't break if an exception is caught in the same function from which it is thrown return False, frame if exception_breakpoint.notify_on_first_raise_only: if main_debugger.skip_on_exceptions_thrown_in_same_context: # In this case we never stop if it was just raised, so, to know if it was the first we # need to check if we're in the 2nd method. if not was_just_raised and not just_raised(trace.tb_next): return False, frame # I.e.: we stop only when we're at the caller of a method that throws an exception else: if not was_just_raised: return False, frame # I.e.: we stop only when it was just raised # If it got here we should stop. should_stop = True try: info.pydev_message = exception_breakpoint.qname except: info.pydev_message = exception_breakpoint.qname.encode('utf-8') # Always add exception to frame (must remove later after we proceed). add_exception_to_frame(frame, (exception, value, trace)) else: # No regular exception breakpoint, let's see if some plugin handles it. try: if main_debugger.plugin is not None: result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) if result: should_stop, frame = result except: should_stop = False if should_stop: if exception_breakpoint is not None and exception_breakpoint.expression is not None: main_debugger.handle_breakpoint_expression(exception_breakpoint, info, frame) return should_stop, frame
def should_stop_on_exception(self, frame, event, arg): # ENDIF # main_debugger, _filename, info, _thread = self._args main_debugger = self._args[0] info = self._args[2] flag = False # STATE_SUSPEND = 2 if info.pydev_state != 2: #and breakpoint is not None: exception, value, trace = arg if trace is not None: #on jython trace is None on the first event exception_breakpoint = get_exception_breakpoint( exception, main_debugger.break_on_caught_exceptions) is_real = is_real_file(frame.f_code.co_filename) if exception_breakpoint is not None: add_exception_to_frame(frame, (exception, value, trace)) if exception_breakpoint.condition is not None: eval_result = handle_breakpoint_condition(main_debugger, info, exception_breakpoint, frame) if not eval_result: return False, frame if exception_breakpoint.ignore_libraries: if exception_breakpoint.notify_on_first_raise_only: if main_debugger.first_appearance_in_scope(trace): add_exception_to_frame(frame, (exception, value, trace)) try: info.pydev_message = exception_breakpoint.qname except: info.pydev_message = exception_breakpoint.qname.encode('utf-8') flag = True else: pydev_log.debug("Ignore exception %s in library %s" % (exception, frame.f_code.co_filename)) flag = False else: if not exception_breakpoint.notify_on_first_raise_only or just_raised(trace): add_exception_to_frame(frame, (exception, value, trace)) try: info.pydev_message = exception_breakpoint.qname except: info.pydev_message = exception_breakpoint.qname.encode('utf-8') flag = True else: flag = False if flag: info.pydev_message = "python-%s" % info.pydev_message if exception_breakpoint is None or (not flag and not is_real): try: if main_debugger.plugin is not None: result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) if result: flag, frame = result except: flag = False if flag: if exception_breakpoint is not None and exception_breakpoint.expression is not None: handle_breakpoint_expression(exception_breakpoint, info, frame) else: remove_exception_from_frame(frame) return flag, frame
def _excepthook(exctype, value, tb): from _pydevd_bundle.pydevd_frame import handle_breakpoint_condition, handle_breakpoint_expression global _handle_exceptions if _handle_exceptions: exception_breakpoint = get_exception_breakpoint( exctype, _handle_exceptions) else: exception_breakpoint = None #Always call the original excepthook before going on to call the debugger post mortem to show it. _original_excepthook(exctype, value, tb) if not exception_breakpoint: return if tb is None: #sometimes it can be None, e.g. with GTK return if exctype is KeyboardInterrupt: return frames = [] debugger = get_global_debugger() user_frame = None while tb: frame = tb.tb_frame if exception_breakpoint.ignore_libraries and not debugger.not_in_scope( frame.f_code.co_filename): user_frame = tb.tb_frame frames.append(tb.tb_frame) tb = tb.tb_next thread = threadingCurrentThread() frames_byid = dict([(id(frame), frame) for frame in frames]) if exception_breakpoint.ignore_libraries and user_frame is not None: frame = user_frame else: frame = frames[-1] exception = (exctype, value, tb) _set_additional_info_if_needed(thread) info = thread.additional_info add_exception_to_frame(frame, exception) if exception_breakpoint.condition is not None: eval_result = handle_breakpoint_condition(debugger, info, exception_breakpoint, frame) if not eval_result: return if exception_breakpoint.expression is not None: handle_breakpoint_expression(exception_breakpoint, info, frame) try: thread.additional_info.pydev_message = exception_breakpoint.qname except: thread.additional_info.pydev_message = exception_breakpoint.qname.encode( 'utf-8') pydevd_tracing.SetTrace(None) #no tracing from here pydev_log.debug('Handling post-mortem stop on exception breakpoint %s' % exception_breakpoint.qname) debugger.handle_post_mortem_stop(thread, frame, frames_byid, exception)
def should_stop_on_exception(self, frame, event, arg): # ENDIF # main_debugger, _filename, info, _thread = self._args main_debugger = self._args[0] info = self._args[2] should_stop = False # STATE_SUSPEND = 2 if info.pydev_state != 2: # and breakpoint is not None: exception, value, trace = arg if trace is not None and hasattr(trace, 'tb_next'): # on jython trace is None on the first event and it may not have a tb_next. should_stop = False exception_breakpoint = None try: if main_debugger.plugin is not None: result = main_debugger.plugin.exception_break( main_debugger, self, frame, self._args, arg) if result: should_stop, frame = result except: pydev_log.exception() if not should_stop: # It was not handled by any plugin, lets check exception breakpoints. exception_breakpoint = main_debugger.get_exception_breakpoint( exception, main_debugger.break_on_caught_exceptions) if exception_breakpoint is not None: if exception is SystemExit and main_debugger.ignore_system_exit_code( value): return False, frame if exception in (GeneratorExit, StopIteration): # These exceptions are control-flow related (they work as a generator # pause), so, we shouldn't stop on them. return False, frame if exception_breakpoint.condition is not None: eval_result = main_debugger.handle_breakpoint_condition( info, exception_breakpoint, frame) if not eval_result: return False, frame if main_debugger.exclude_exception_by_filter( exception_breakpoint, trace, False): pydev_log.debug( "Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) return False, frame if ignore_exception_trace(trace): return False, frame was_just_raised = just_raised(trace) if was_just_raised: if main_debugger.skip_on_exceptions_thrown_in_same_context: # Option: Don't break if an exception is caught in the same function from which it is thrown return False, frame if exception_breakpoint.notify_on_first_raise_only: if main_debugger.skip_on_exceptions_thrown_in_same_context: # In this case we never stop if it was just raised, so, to know if it was the first we # need to check if we're in the 2nd method. if not was_just_raised and not just_raised( trace.tb_next): return False, frame # I.e.: we stop only when we're at the caller of a method that throws an exception else: if not was_just_raised: return False, frame # I.e.: we stop only when it was just raised # If it got here we should stop. should_stop = True try: info.pydev_message = exception_breakpoint.qname except: info.pydev_message = exception_breakpoint.qname.encode( 'utf-8') if should_stop: # Always add exception to frame (must remove later after we proceed). add_exception_to_frame(frame, (exception, value, trace)) if exception_breakpoint is not None and exception_breakpoint.expression is not None: main_debugger.handle_breakpoint_expression( exception_breakpoint, info, frame) return should_stop, frame
def should_stop_on_exception(self, frame, event, arg): # ENDIF # main_debugger, _filename, info, _thread = self._args main_debugger = self._args[0] info = self._args[2] should_stop = False # STATE_SUSPEND = 2 if info.pydev_state != 2: # and breakpoint is not None: exception, value, trace = arg if trace is not None and hasattr(trace, 'tb_next'): # on jython trace is None on the first event and it may not have a tb_next. should_stop = False exception_breakpoint = None try: if main_debugger.plugin is not None: result = main_debugger.plugin.exception_break( main_debugger, self, frame, self._args, arg) if result: should_stop, frame = result except: pydev_log.exception() if not should_stop: was_just_raised = trace.tb_next is None # It was not handled by any plugin, lets check exception breakpoints. check_excs = [] exc_break_caught = main_debugger.get_exception_breakpoint( exception, main_debugger.break_on_caught_exceptions) if exc_break_caught is not None: check_excs.append((exc_break_caught, False)) exc_break_user = main_debugger.get_exception_breakpoint( exception, main_debugger.break_on_user_uncaught_exceptions) if exc_break_user is not None: check_excs.append((exc_break_user, True)) for exc_break, is_user_uncaught in check_excs: # Initially mark that it should stop and then go into exclusions. should_stop = True if exception is SystemExit and main_debugger.ignore_system_exit_code( value): should_stop = False elif exception in (GeneratorExit, StopIteration): # These exceptions are control-flow related (they work as a generator # pause), so, we shouldn't stop on them. should_stop = False elif main_debugger.exclude_exception_by_filter( exc_break, trace): pydev_log.debug( "Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) should_stop = False elif ignore_exception_trace(trace): should_stop = False elif exc_break.condition is not None and \ not main_debugger.handle_breakpoint_condition(info, exc_break, frame): should_stop = False elif was_just_raised and main_debugger.skip_on_exceptions_thrown_in_same_context: # Option: Don't break if an exception is caught in the same function from which it is thrown should_stop = False elif exc_break.notify_on_first_raise_only and main_debugger.skip_on_exceptions_thrown_in_same_context \ and not was_just_raised and not just_raised(trace.tb_next): # In this case we never stop if it was just raised, so, to know if it was the first we # need to check if we're in the 2nd method. should_stop = False # I.e.: we stop only when we're at the caller of a method that throws an exception elif exc_break.notify_on_first_raise_only and not main_debugger.skip_on_exceptions_thrown_in_same_context \ and not was_just_raised: should_stop = False # I.e.: we stop only when it was just raised elif is_user_uncaught and not ( not main_debugger.apply_files_filter( frame, frame.f_code.co_filename, True) and (frame.f_back is None or main_debugger.apply_files_filter( frame.f_back, frame.f_back.f_code.co_filename, True))): # User uncaught means that we're currently in user code but the code # up the stack is library code. should_stop = False if should_stop: exception_breakpoint = exc_break try: info.pydev_message = exc_break.qname except: info.pydev_message = exc_break.qname.encode( 'utf-8') break if should_stop: # Always add exception to frame (must remove later after we proceed). add_exception_to_frame(frame, (exception, value, trace)) if exception_breakpoint is not None and exception_breakpoint.expression is not None: main_debugger.handle_breakpoint_expression( exception_breakpoint, info, frame) return should_stop, frame
def should_stop_on_exception(self, frame, event, arg): # ENDIF # main_debugger, _filename, info, _thread = self._args main_debugger = self._args[0] info = self._args[2] should_stop = False # STATE_SUSPEND = 2 if info.pydev_state != 2: # and breakpoint is not None: exception, value, trace = arg if trace is not None and hasattr(trace, 'tb_next'): # on jython trace is None on the first event and it may not have a tb_next. exception_breakpoint = get_exception_breakpoint( exception, main_debugger.break_on_caught_exceptions) if exception_breakpoint is not None: if exception_breakpoint.condition is not None: eval_result = handle_breakpoint_condition(main_debugger, info, exception_breakpoint, frame) if not eval_result: return False, frame if exception_breakpoint.ignore_libraries: if not main_debugger.is_exception_trace_in_project_scope(trace): pydev_log.debug("Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) return False, frame if ignore_exception_trace(trace): return False, frame was_just_raised = just_raised(trace) if was_just_raised: if main_debugger.skip_on_exceptions_thrown_in_same_context: # Option: Don't break if an exception is caught in the same function from which it is thrown return False, frame if exception_breakpoint.notify_on_first_raise_only: if main_debugger.skip_on_exceptions_thrown_in_same_context: # In this case we never stop if it was just raised, so, to know if it was the first we # need to check if we're in the 2nd method. if not was_just_raised and not just_raised(trace.tb_next): return False, frame # I.e.: we stop only when we're at the caller of a method that throws an exception else: if not was_just_raised: return False, frame # I.e.: we stop only when it was just raised # If it got here we should stop. should_stop = True try: info.pydev_message = exception_breakpoint.qname except: info.pydev_message = exception_breakpoint.qname.encode('utf-8') # Always add exception to frame (must remove later after we proceed). add_exception_to_frame(frame, (exception, value, trace)) else: # No regular exception breakpoint, let's see if some plugin handles it. try: if main_debugger.plugin is not None: result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) if result: should_stop, frame = result except: should_stop = False if should_stop: if exception_breakpoint is not None and exception_breakpoint.expression is not None: handle_breakpoint_expression(exception_breakpoint, info, frame) return should_stop, frame
def handle_exception(self, frame, event, arg): try: # We have 3 things in arg: exception type, description, traceback object trace_obj = arg[2] main_debugger = self._args[0] initial_trace_obj = trace_obj if trace_obj.tb_next is None and trace_obj.tb_frame is frame: # I.e.: tb_next should be only None in the context it was thrown (trace_obj.tb_frame is frame is just a double check). pass else: # Get the trace_obj from where the exception was raised... while trace_obj.tb_next is not None: trace_obj = trace_obj.tb_next if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception \ and not main_debugger.stop_on_failed_tests: for check_trace_obj in (initial_trace_obj, trace_obj): filename = get_abs_path_real_path_and_base_from_frame( check_trace_obj.tb_frame)[1] filename_to_lines_where_exceptions_are_ignored = self.filename_to_lines_where_exceptions_are_ignored lines_ignored = filename_to_lines_where_exceptions_are_ignored.get( filename) if lines_ignored is None: lines_ignored = filename_to_lines_where_exceptions_are_ignored[ filename] = {} try: curr_stat = os.stat(filename) curr_stat = (curr_stat.st_size, curr_stat.st_mtime) except: curr_stat = None last_stat = self.filename_to_stat_info.get(filename) if last_stat != curr_stat: self.filename_to_stat_info[filename] = curr_stat lines_ignored.clear() try: linecache.checkcache(filename) except: # Jython 2.1 linecache.checkcache() from_user_input = main_debugger.filename_to_lines_where_exceptions_are_ignored.get( filename) if from_user_input: merged = {} merged.update(lines_ignored) # Override what we have with the related entries that the user entered merged.update(from_user_input) else: merged = lines_ignored exc_lineno = check_trace_obj.tb_lineno # print ('lines ignored', lines_ignored) # print ('user input', from_user_input) # print ('merged', merged, 'curr', exc_lineno) if exc_lineno not in merged: # Note: check on merged but update lines_ignored. try: line = linecache.getline( filename, exc_lineno, check_trace_obj.tb_frame.f_globals) except: # Jython 2.1 line = linecache.getline(filename, exc_lineno) if IGNORE_EXCEPTION_TAG.match(line) is not None: lines_ignored[exc_lineno] = 1 return else: # Put in the cache saying not to ignore lines_ignored[exc_lineno] = 0 else: # Ok, dict has it already cached, so, let's check it... if merged.get(exc_lineno, 0): return thread = self._args[3] try: frame_id_to_frame = {} frame_id_to_frame[id(frame)] = frame f = trace_obj.tb_frame while f is not None: frame_id_to_frame[id(f)] = f f = f.f_back f = None thread_id = get_current_thread_id(thread) if main_debugger.stop_on_failed_tests: # Our goal is to find the deepest frame in stack that still belongs to the project and stop there. f = trace_obj.tb_frame while f: abs_path, _, _ = get_abs_path_real_path_and_base_from_frame( f) if main_debugger.in_project_scope(abs_path): frame = f break f = f.f_back f = None trace_obj = initial_trace_obj while trace_obj: if trace_obj.tb_frame is frame: break trace_obj = trace_obj.tb_next add_exception_to_frame(frame, (arg[0], arg[1], trace_obj)) pydevd_vars.add_additional_frame_by_id(thread_id, frame_id_to_frame) try: main_debugger.send_caught_exception_stack( thread, arg, id(frame)) self.set_suspend(thread, CMD_STEP_CAUGHT_EXCEPTION) self.do_wait_suspend(thread, frame, event, arg) main_debugger.send_caught_exception_stack_proceeded(thread) finally: pydevd_vars.remove_additional_frame_by_id(thread_id) except KeyboardInterrupt as e: raise e except: traceback.print_exc() main_debugger.set_trace_for_frame_and_parents(frame) finally: # Make sure the user cannot see the '__exception__' we added after we leave the suspend state. remove_exception_from_frame(frame) # Clear some local variables... frame = None trace_obj = None initial_trace_obj = None check_trace_obj = None f = None frame_id_to_frame = None main_debugger = None thread = None