Exemple #1
0
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)
Exemple #2
0
def _set_additional_info_if_needed(thread):
    try:
        additional_info = thread.additional_info
        if additional_info is None:
            raise AttributeError()
    except:
        from _pydevd_bundle.pydevd_additional_thread_info import PyDBAdditionalThreadInfo
        thread.additional_info = PyDBAdditionalThreadInfo()
Exemple #3
0
def break_into_debugger():
    """If a remote debugger is attached, pauses execution of all threads,
    and breaks into the debugger with current thread as active.
    """
    debugger = get_global_debugger()
    if not _attached.isSet() or debugger is None:
        return

    thread = pydevd.threadingCurrentThread()
    try:
        additional_info = thread.additional_info
    except AttributeError:
        additional_info = PyDBAdditionalThreadInfo()
        thread.additional_info = additional_info

    debugger.set_suspend(thread, CMD_THREAD_SUSPEND)
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).
    from os.path import basename, splitext
    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 py_db.trace_dispatch

            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 == '_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 = thread.additional_info = PyDBAdditionalThreadInfo()

    # 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', 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)