def run(*args, **kwargs): debugger = get_global_debugger() if debugger is not None: SetTrace(debugger.trace_dispatch) debugger = None return _original_run(*args, **kwargs)
def trace_dispatch(py_db, frame, event, arg): #try: t = threadingCurrentThread() #except: #this could give an exception (python 2.5 bug), but should not be there anymore... #see http://mail.python.org/pipermail/python-bugs-list/2007-June/038796.html #and related bug: http://bugs.python.org/issue1733757 #frame.f_trace = py_db.trace_dispatch #return py_db.trace_dispatch if getattr(t, 'pydev_do_not_trace', None): return None try: additional_info = t.additional_info if additional_info is None: raise AttributeError() except: additional_info = t.additional_info = PyDBAdditionalThreadInfo() thread_tracer = ThreadTracer((py_db, t, additional_info)) # IFDEF CYTHON # t._tracer = thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). # ELSE # ENDIF SetTrace(thread_tracer.__call__) return thread_tracer.__call__(frame, event, arg)
def new_f(old_f, args, kwargs): debugger = get_global_debugger() if debugger is not None: SetTrace(debugger.trace_dispatch) debugger = None # Remove our own traces :) self.tempval = old_f register_tasklet_info(self) # Hover old_f to see the stackless being created and *args and **kwargs to see its parameters. return old_f(*args, **kwargs)
def run(*args, **kwargs): debugger = GetGlobalDebugger() if debugger is not None: SetTrace(debugger.trace_dispatch) f_back = sys._getframe().f_back frameId = addCustomFrame(f_back, 'Main Tasklet Run') tasklet_id = id(f_back) id_to_tasklet_frame[tasklet_id] = frameId try: return _original_run(*args, **kwargs) finally: removeCustomFrame(frameId) del id_to_tasklet_frame[tasklet_id]
def new_f(old_f, args, kwargs): debugger = GetGlobalDebugger() if debugger is not None: SetTrace(debugger.trace_dispatch) frameId = addCustomFrame(caller_frame, 'Tasklet') tasklet_id = id(self) id_to_tasklet_frame[tasklet_id] = frameId try: # Note: if the debugger appears in the line below, it means that a tasklet was created # but it's still not running. # Hover old_f to see the stackless being created and *args and **kwargs to see its parameters. old_f(*args, **kwargs) finally: removeCustomFrame(frameId) del id_to_tasklet_frame[tasklet_id]
def trace_dispatch(py_db, frame, event, arg): t = threadingCurrentThread() if getattr(t, 'pydev_do_not_trace', None): return None try: additional_info = t.additional_info if additional_info is None: raise AttributeError() except: additional_info = t.additional_info = PyDBAdditionalThreadInfo() thread_tracer = ThreadTracer((py_db, t, additional_info, global_cache_skips, global_cache_frame_skips)) # IFDEF CYTHON # t._tracer = thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). # ELSE # ENDIF SetTrace(thread_tracer.__call__) return thread_tracer.__call__(frame, event, arg)
def trace_dispatch(py_db, frame, event, arg): # Note: this is always the first entry-point in the tracing for any thread. # After entering here we'll set a new tracing function for this thread # where more information is cached (and will also setup the tracing for # frames where we should deal with unhandled exceptions). thread = None # Cache the frame which should be traced to deal with unhandled exceptions. # (i.e.: thread entry-points). f_unhandled = frame only_trace_for_unhandled_exceptions = True # print('called at', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) while f_unhandled is not None: filename = f_unhandled.f_code.co_filename name = splitext(basename(filename))[0] if name == 'threading': if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): # We need __bootstrap_inner, not __bootstrap. return None elif f_unhandled.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'): # Note: be careful not to use threading.currentThread to avoid creating a dummy thread. t = f_unhandled.f_locals.get('self') if t is not None and isinstance(t, threading.Thread): thread = t only_trace_for_unhandled_exceptions = True break elif name == 'pydevd': if f_unhandled.f_code.co_name in ('run', 'main'): # We need to get to _exec return None if f_unhandled.f_code.co_name == '_exec': only_trace_for_unhandled_exceptions = True break elif f_unhandled.f_back is None: only_trace_for_unhandled_exceptions = False break f_unhandled = f_unhandled.f_back if thread is None: # Important: don't call threadingCurrentThread if we're in the threading module # to avoid creating dummy threads. thread = threadingCurrentThread() if getattr(thread, 'pydev_do_not_trace', None): SetTrace(None, apply_to_pydevd_thread=True) return None try: additional_info = thread.additional_info if additional_info is None: raise AttributeError() except: additional_info = set_additional_thread_info(thread) # print('enter thread tracer', thread, get_thread_id(thread)) thread_tracer = ThreadTracer((py_db, thread, additional_info, global_cache_skips, global_cache_frame_skips)) if f_unhandled is not None: # print(' --> found to trace unhandled', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) if only_trace_for_unhandled_exceptions: f_trace = thread_tracer.trace_unhandled_exceptions else: f_trace = thread_tracer.trace_dispatch_and_unhandled_exceptions # IFDEF CYTHON # f_unhandled.f_trace = SafeCallWrapper(f_trace) # ELSE f_unhandled.f_trace = f_trace # ENDIF if frame is f_unhandled: if only_trace_for_unhandled_exceptions: return thread_tracer.trace_unhandled_exceptions(frame, event, arg) else: return thread_tracer.trace_dispatch_and_unhandled_exceptions(frame, event, arg) # IFDEF CYTHON # thread._tracer = thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). # ELSE # ENDIF SetTrace(thread_tracer.__call__) return thread_tracer.__call__(frame, event, arg)
def fix_top_level_trace_and_get_trace_func(py_db, frame): # IFDEF CYTHON # cdef str filename; # cdef str name; # cdef tuple args; # ENDIF # Note: this is always the first entry-point in the tracing for any thread. # After entering here we'll set a new tracing function for this thread # where more information is cached (and will also setup the tracing for # frames where we should deal with unhandled exceptions). thread = None # Cache the frame which should be traced to deal with unhandled exceptions. # (i.e.: thread entry-points). f_unhandled = frame # print('called at', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) force_only_unhandled_tracer = False while f_unhandled is not None: filename = f_unhandled.f_code.co_filename name = splitext(basename(filename))[0] if name == 'threading': if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): # We need __bootstrap_inner, not __bootstrap. return None, False elif f_unhandled.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'): # Note: be careful not to use threading.currentThread to avoid creating a dummy thread. t = f_unhandled.f_locals.get('self') force_only_unhandled_tracer = True if t is not None and isinstance(t, threading.Thread): thread = t break elif name == 'pydev_monkey': if f_unhandled.f_code.co_name == '__call__': force_only_unhandled_tracer = True break elif name == 'pydevd': if f_unhandled.f_code.co_name in ('run', 'main'): # We need to get to _exec return None, False if f_unhandled.f_code.co_name == '_exec': force_only_unhandled_tracer = True break elif f_unhandled.f_back is None: break f_unhandled = f_unhandled.f_back if thread is None: # Important: don't call threadingCurrentThread if we're in the threading module # to avoid creating dummy threads. if threading_get_ident is not None: thread = threading._active.get(threading_get_ident()) if thread is None: return None, False else: # Jython does not have threading.get_ident(). thread = threadingCurrentThread() if getattr(thread, 'pydev_do_not_trace', None): SetTrace(None) return None, False try: additional_info = thread.additional_info if additional_info is None: raise AttributeError() except: additional_info = set_additional_thread_info(thread) # print('enter thread tracer', thread, get_current_thread_id(thread)) args = (py_db, thread, additional_info, global_cache_skips, global_cache_frame_skips) if f_unhandled is not None: if f_unhandled.f_back is None and not force_only_unhandled_tracer: # Happens when we attach to a running program. top_level_thread_tracer = TopLevelThreadTracerNoBackFrame(ThreadTracer(args), args) else: # Stop in some internal place to report about unhandled exceptions top_level_thread_tracer = TopLevelThreadTracerOnlyUnhandledExceptions(args) # IFDEF CYTHON # thread._top_level_thread_tracer = top_level_thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). # ELSE # ENDIF # print(' --> found to trace unhandled', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) f_trace = top_level_thread_tracer.get_trace_dispatch_func() # IFDEF CYTHON # f_unhandled.f_trace = SafeCallWrapper(f_trace) # ELSE f_unhandled.f_trace = f_trace # ENDIF if frame is f_unhandled: return f_unhandled.f_trace, False thread_tracer = ThreadTracer(args) # IFDEF CYTHON # thread._tracer = thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). # ELSE # ENDIF return thread_tracer, True