diff options
Diffstat (limited to 'python/helpers/pydev/pydevd.py')
-rw-r--r-- | python/helpers/pydev/pydevd.py | 185 |
1 files changed, 108 insertions, 77 deletions
diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index 9d0da096c07d..8d68cea9876c 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -3,12 +3,15 @@ from __future__ import nested_scopes # Jython 2.1 support from pydevd_constants import * # @UnusedWildImport import pydev_monkey_qt +from pydevd_utils import save_main_module + pydev_monkey_qt.patch_qt() import traceback -from django_debug import DjangoLineBreakpoint -from pydevd_frame import add_exception_to_frame +from pydevd_plugin_utils import PluginManager + +from pydevd_frame_utils import add_exception_to_frame import pydev_imports from pydevd_breakpoints import * #@UnusedWildImport import fix_getpass @@ -110,13 +113,18 @@ DONT_TRACE = { 'linecache.py':1, 'threading.py':1, + # thirs party libs that we don't want to trace + 'pluginbase.py':1, + 'pkgutil_old.py':1, + 'uuid_old.py':1, + #things from pydev that we don't want to trace '_pydev_execfile.py':1, '_pydev_jython_execfile.py':1, '_pydev_threading':1, '_pydev_Queue':1, 'django_debug.py':1, - 'django_frame.py':1, + 'jinja2_debug.py':1, 'pydev_log.py':1, 'pydev_monkey.py':1 , 'pydevd.py':1 , @@ -301,17 +309,15 @@ class PyDB: self._cmd_queue = {} # the hash of Queues. Key is thread id, value is thread self.breakpoints = {} - self.django_breakpoints = {} self.file_to_id_to_line_breakpoint = {} - self.file_to_id_to_django_breakpoint = {} + self.file_to_id_to_plugin_breakpoint = {} # Note: breakpoints dict should not be mutated: a copy should be created # and later it should be assigned back (to prevent concurrency issues). self.break_on_uncaught_exceptions = {} self.break_on_caught_exceptions = {} - self.django_exception_break = {} self.readyToRun = False self._main_lock = _pydev_thread.allocate_lock() self._lock_running_thread_ids = _pydev_thread.allocate_lock() @@ -344,6 +350,8 @@ class PyDB: # This attribute holds the file-> lines which have an @IgnoreException. self.filename_to_lines_where_exceptions_are_ignored = {} + #working with plugins + self.plugin = PluginManager(self) def haveAliveThreads(self): for t in threadingEnumerate(): @@ -568,12 +576,16 @@ class PyDB: notify_on_terminate, notify_on_first_raise_only, ): - eb = ExceptionBreakpoint( - exception, - notify_always, - notify_on_terminate, - notify_on_first_raise_only, - ) + try: + eb = ExceptionBreakpoint( + exception, + notify_always, + notify_on_terminate, + notify_on_first_raise_only, + ) + except ImportError: + pydev_log.error("Error unable to add break on exception for: %s (exception could not be imported)\n" % (exception,)) + return None if eb.notify_on_terminate: cp = self.break_on_uncaught_exceptions.copy() @@ -839,15 +851,22 @@ class PyDB: if len(expression) <= 0 or expression is None or expression == "None": expression = None + supported_type = False if type == 'python-line': breakpoint = LineBreakpoint(line, condition, func_name, expression) breakpoints = self.breakpoints file_to_id_to_breakpoint = self.file_to_id_to_line_breakpoint - elif type == 'django-line': - breakpoint = DjangoLineBreakpoint(file, line, condition, func_name, expression) - breakpoints = self.django_breakpoints - file_to_id_to_breakpoint = self.file_to_id_to_django_breakpoint + supported_type = True else: + result = self.plugin.add_breakpoint('add_line_breakpoint', self, type, file, line, condition, expression, func_name) + if result is not None: + supported_type = True + breakpoint, breakpoints = result + file_to_id_to_breakpoint = self.file_to_id_to_plugin_breakpoint + else: + supported_type = False + + if not supported_type: raise NameError(type) if DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS > 0: @@ -880,27 +899,31 @@ class PyDB: pydev_log.error('Error removing breakpoint. Expected breakpoint_id to be an int. Found: %s' % (breakpoint_id,)) else: + file_to_id_to_breakpoint = None if breakpoint_type == 'python-line': breakpoints = self.breakpoints file_to_id_to_breakpoint = self.file_to_id_to_line_breakpoint - elif breakpoint_type == 'django-line': - breakpoints = self.django_breakpoints - file_to_id_to_breakpoint = self.file_to_id_to_django_breakpoint else: - raise NameError(breakpoint_type) + result = self.plugin.get_breakpoints(self, breakpoint_type) + if result is not None: + file_to_id_to_breakpoint = self.file_to_id_to_plugin_breakpoint + breakpoints = result - try: - id_to_pybreakpoint = file_to_id_to_breakpoint.get(file, {}) - if DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS > 0: - existing = id_to_pybreakpoint[breakpoint_id] - sys.stderr.write('Removed breakpoint:%s - line:%s - func_name:%s (id: %s)\n' % ( - file, existing.line, existing.func_name.encode('utf-8'), breakpoint_id)) + if file_to_id_to_breakpoint is None: + pydev_log.error('Error removing breakpoint. Cant handle breakpoint of type %s' % breakpoint_type) + else: + try: + id_to_pybreakpoint = file_to_id_to_breakpoint.get(file, {}) + if DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS > 0: + existing = id_to_pybreakpoint[breakpoint_id] + sys.stderr.write('Removed breakpoint:%s - line:%s - func_name:%s (id: %s)\n' % ( + file, existing.line, existing.func_name.encode('utf-8'), breakpoint_id)) - del id_to_pybreakpoint[breakpoint_id] - self.consolidate_breakpoints(file, id_to_pybreakpoint, breakpoints) - except KeyError: - pydev_log.error("Error removing breakpoint: Breakpoint id not found: %s id: %s. Available ids: %s\n" % ( - file, breakpoint_id, DictKeys(id_to_pybreakpoint))) + del id_to_pybreakpoint[breakpoint_id] + self.consolidate_breakpoints(file, id_to_pybreakpoint, breakpoints) + except KeyError: + pydev_log.error("Error removing breakpoint: Breakpoint id not found: %s id: %s. Available ids: %s\n" % ( + file, breakpoint_id, DictKeys(id_to_pybreakpoint))) elif cmd_id == CMD_EVALUATE_EXPRESSION or cmd_id == CMD_EXEC_EXPRESSION: @@ -963,6 +986,8 @@ class PyDB: notify_on_terminate=break_on_uncaught, notify_on_first_raise_only=False, ) + if exception_breakpoint is None: + continue added.append(exception_breakpoint) self.update_after_exceptions_added(added) @@ -1013,28 +1038,58 @@ class PyDB: pass elif cmd_id == CMD_ADD_EXCEPTION_BREAK: - exception, notify_always, notify_on_terminate = text.split('\t', 2) - exception_breakpoint = self.add_break_on_exception( - exception, - notify_always=int(notify_always) > 0, - notify_on_terminate = int(notify_on_terminate) == 1, - notify_on_first_raise_only=int(notify_always) == 2 - ) - self.update_after_exceptions_added([exception_breakpoint]) + if text.find('\t') != -1: + exception, notify_always, notify_on_terminate = text.split('\t', 2) + else: + exception, notify_always, notify_on_terminate = text, 0, 0 + + if exception.find('-') != -1: + type, exception = exception.split('-') + else: + type = 'python' + + if type == 'python': + exception_breakpoint = self.add_break_on_exception( + exception, + notify_always=int(notify_always) > 0, + notify_on_terminate = int(notify_on_terminate) == 1, + notify_on_first_raise_only=int(notify_always) == 2 + ) + + if exception_breakpoint is not None: + self.update_after_exceptions_added([exception_breakpoint]) + else: + supported_type = self.plugin.add_breakpoint('add_exception_breakpoint', self, type, exception) + + if not supported_type: + raise NameError(type) + + elif cmd_id == CMD_REMOVE_EXCEPTION_BREAK: exception = text - try: - cp = self.break_on_uncaught_exceptions.copy() - DictPop(cp, exception, None) - self.break_on_uncaught_exceptions = cp + if exception.find('-') != -1: + type, exception = exception.split('-') + else: + type = 'python' - cp = self.break_on_caught_exceptions.copy() - DictPop(cp, exception, None) - self.break_on_caught_exceptions = cp - except: - pydev_log.debug("Error while removing exception %s"%sys.exc_info()[0]); - update_exception_hook(self) + if type == 'python': + try: + cp = self.break_on_uncaught_exceptions.copy() + DictPop(cp, exception, None) + self.break_on_uncaught_exceptions = cp + + cp = self.break_on_caught_exceptions.copy() + DictPop(cp, exception, None) + self.break_on_caught_exceptions = cp + except: + pydev_log.debug("Error while removing exception %s"%sys.exc_info()[0]) + update_exception_hook(self) + else: + supported_type = self.plugin.remove_exception_breakpoint(self, type, exception) + + if not supported_type: + raise NameError(type) elif cmd_id == CMD_LOAD_SOURCE: path = text @@ -1048,16 +1103,13 @@ class PyDB: elif cmd_id == CMD_ADD_DJANGO_EXCEPTION_BREAK: exception = text - self.django_exception_break[exception] = True - self.setTracingForUntracedContexts() + self.plugin.add_breakpoint('add_exception_breakpoint', self, 'django', exception) + elif cmd_id == CMD_REMOVE_DJANGO_EXCEPTION_BREAK: exception = text - try: - del self.django_exception_break[exception] - except : - pass + self.plugin.remove_exception_breakpoint(self, 'django', exception) elif cmd_id == CMD_EVALUATE_CONSOLE_EXPRESSION: # Command which takes care for the debug console communication @@ -1492,22 +1544,7 @@ class PyDB: file = new_target if globals is None: - # patch provided by: Scott Schlesier - when script is run, it does not - # use globals from pydevd: - # This will prevent the pydevd script from contaminating the namespace for the script to be debugged - - # pretend pydevd is not the main module, and - # convince the file to be debugged that it was loaded as main - sys.modules['pydevd'] = sys.modules['__main__'] - sys.modules['pydevd'].__name__ = 'pydevd' - - from imp import new_module - m = new_module('__main__') - sys.modules['__main__'] = m - if hasattr(sys.modules['pydevd'], '__loader__'): - setattr(m, '__loader__', getattr(sys.modules['pydevd'], '__loader__')) - - m.__file__ = file + m = save_main_module(file, 'pydevd') globals = m.__dict__ try: globals['__builtins__'] = __builtins__ @@ -1546,8 +1583,6 @@ class PyDB: pydev_imports.execfile(file, globals, locals) # execute the script - return globals - def exiting(self): sys.stdout.flush() sys.stderr.flush() @@ -2061,10 +2096,6 @@ if __name__ == '__main__': debugger = PyDB() - if setup['cmd-line']: - debugger.cmd_line = True - - if fix_app_engine_debug: sys.stderr.write("pydev debugger: google app engine integration enabled\n") curr_dir = os.path.dirname(__file__) |