def process_net_command(self, py_db, cmd_id, seq, text): '''Processes a command received from the Java side @param cmd_id: the id of the command @param seq: the sequence of the command @param text: the text received in the command ''' # We can only proceed if the client is already authenticated or if it's the # command to authenticate. if cmd_id != CMD_AUTHENTICATE and not py_db.authentication.is_authenticated(): cmd = py_db.cmd_factory.make_error_message(seq, 'Client not authenticated.') py_db.writer.add_command(cmd) return meaning = ID_TO_MEANING[str(cmd_id)] # print('Handling %s (%s)' % (meaning, text)) method_name = meaning.lower() on_command = getattr(self, method_name.lower(), None) if on_command is None: # I have no idea what this is all about cmd = py_db.cmd_factory.make_error_message(seq, "unexpected command " + str(cmd_id)) py_db.writer.add_command(cmd) return lock = py_db._main_lock if method_name == 'cmd_thread_dump_to_stderr': # We can skip the main debugger locks for cases where we know it's not needed. lock = NULL with lock: try: cmd = on_command(py_db, cmd_id, seq, text) if cmd is not None: py_db.writer.add_command(cmd) except: if traceback is not None and sys is not None and pydev_log_exception is not None: pydev_log_exception() stream = StringIO() traceback.print_exc(file=stream) cmd = py_db.cmd_factory.make_error_message( seq, "Unexpected exception in process_net_command.\nInitial params: %s. Exception: %s" % ( ((cmd_id, seq, text), stream.getvalue()) ) ) if cmd is not None: py_db.writer.add_command(cmd)
def run(self): created_pydb_daemon = self.py_db.created_pydb_daemon_threads created_pydb_daemon[self] = 1 try: try: if IS_JYTHON and not isinstance(threading.currentThread(), threading._MainThread): # we shouldn't update sys.modules for the main thread, cause it leads to the second importing 'threading' # module, and the new instance of main thread is created ss = JyCore.PySystemState() # Note: Py.setSystemState() affects only the current thread. JyCore.Py.setSystemState(ss) self._stop_trace() self._on_run() except: if sys is not None and pydev_log_exception is not None: pydev_log_exception() finally: del created_pydb_daemon[self]
def process_net_command(self, py_db, cmd_id, seq, text): '''Processes a command received from the Java side @param cmd_id: the id of the command @param seq: the sequence of the command @param text: the text received in the command ''' meaning = ID_TO_MEANING[str(cmd_id)] # print('Handling %s (%s)' % (meaning, text)) method_name = meaning.lower() on_command = getattr(self, method_name.lower(), None) if on_command is None: # I have no idea what this is all about cmd = py_db.cmd_factory.make_error_message(seq, "unexpected command " + str(cmd_id)) py_db.writer.add_command(cmd) return py_db._main_lock.acquire() try: cmd = on_command(py_db, cmd_id, seq, text) if cmd is not None: py_db.writer.add_command(cmd) except: if traceback is not None and sys is not None and pydev_log_exception is not None: pydev_log_exception() stream = StringIO() traceback.print_exc(file=stream) cmd = py_db.cmd_factory.make_error_message( seq, "Unexpected exception in process_net_command.\nInitial params: %s. Exception: %s" % ( ((cmd_id, seq, text), stream.getvalue()) ) ) if cmd is not None: py_db.writer.add_command(cmd) finally: py_db._main_lock.release()
def process_net_command(self, py_db, cmd_id, seq, text): '''Processes a command received from the Java side @param cmd_id: the id of the command @param seq: the sequence of the command @param text: the text received in the command ''' meaning = ID_TO_MEANING[str(cmd_id)] # print('Handling %s (%s)' % (meaning, text)) method_name = meaning.lower() on_command = getattr(self, method_name.lower(), None) if on_command is None: # I have no idea what this is all about cmd = py_db.cmd_factory.make_error_message(seq, "unexpected command " + str(cmd_id)) py_db.writer.add_command(cmd) return py_db._main_lock.acquire() try: cmd = on_command(py_db, cmd_id, seq, text) if cmd is not None: py_db.writer.add_command(cmd) except: if traceback is not None and sys is not None and pydev_log_exception is not None: pydev_log_exception() stream = StringIO() traceback.print_exc(file=stream) cmd = py_db.cmd_factory.make_error_message( seq, "Unexpected exception in process_net_command.\nInitial params: %s. Exception: %s" % ( ((cmd_id, seq, text), stream.getvalue()) ) ) if cmd is not None: py_db.writer.add_command(cmd) finally: py_db._main_lock.release()
def __call__(self, frame, event, arg): ''' This is the callback used when we enter some context in the debugger. We also decorate the thread we are in with info about the debugging. The attributes added are: pydev_state pydev_step_stop pydev_step_cmd pydev_notify_kill :param PyDB py_db: This is the global debugger (this method should actually be added as a method to it). ''' # IFDEF CYTHON # cdef str filename; # cdef str base; # cdef int pydev_step_cmd; # cdef tuple frame_cache_key; # cdef dict cache_skips; # cdef bint is_stepping; # cdef tuple abs_path_canonical_path_and_base; # cdef PyDBAdditionalThreadInfo additional_info; # ENDIF # DEBUG = 'code_to_debug' in frame.f_code.co_filename # if DEBUG: print('ENTER: trace_dispatch: %s %s %s %s' % (frame.f_code.co_filename, frame.f_lineno, event, frame.f_code.co_name)) py_db, t, additional_info, cache_skips, frame_skips_cache = self._args if additional_info.is_tracing: return None if event == 'call' else NO_FTRACE # we don't wan't to trace code invoked from pydevd_frame.trace_dispatch additional_info.is_tracing += 1 try: pydev_step_cmd = additional_info.pydev_step_cmd is_stepping = pydev_step_cmd != -1 if py_db.pydb_disposed: return None if event == 'call' else NO_FTRACE # if thread is not alive, cancel trace_dispatch processing if not is_thread_alive(t): py_db.notify_thread_not_alive(get_current_thread_id(t)) return None if event == 'call' else NO_FTRACE # Note: it's important that the context name is also given because we may hit something once # in the global context and another in the local context. frame_cache_key = (frame.f_code.co_firstlineno, frame.f_code.co_name, frame.f_code.co_filename) if frame_cache_key in cache_skips: if not is_stepping: # if DEBUG: print('skipped: trace_dispatch (cache hit)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) return None if event == 'call' else NO_FTRACE else: # When stepping we can't take into account caching based on the breakpoints (only global filtering). if cache_skips.get(frame_cache_key) == 1: if additional_info.pydev_original_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) and not _global_notify_skipped_step_in: notify_skipped_step_in_because_of_filters(py_db, frame) back_frame = frame.f_back if back_frame is not None and pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE): back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) if cache_skips.get(back_frame_cache_key) == 1: # if DEBUG: print('skipped: trace_dispatch (cache hit: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) return None if event == 'call' else NO_FTRACE else: # if DEBUG: print('skipped: trace_dispatch (cache hit: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) return None if event == 'call' else NO_FTRACE try: # Make fast path faster! abs_path_canonical_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] except: abs_path_canonical_path_and_base = get_abs_path_real_path_and_base_from_frame(frame) file_type = py_db.get_file_type(frame, abs_path_canonical_path_and_base) # we don't want to debug threading or anything related to pydevd if file_type is not None: if file_type == 1: # inlining LIB_FILE = 1 if not py_db.in_project_scope(frame, abs_path_canonical_path_and_base[0]): # if DEBUG: print('skipped: trace_dispatch (not in scope)', abs_path_canonical_path_and_base[2], frame.f_lineno, event, frame.f_code.co_name, file_type) cache_skips[frame_cache_key] = 1 return None if event == 'call' else NO_FTRACE else: # if DEBUG: print('skipped: trace_dispatch', abs_path_canonical_path_and_base[2], frame.f_lineno, event, frame.f_code.co_name, file_type) cache_skips[frame_cache_key] = 1 return None if event == 'call' else NO_FTRACE if py_db.is_files_filter_enabled: if py_db.apply_files_filter(frame, abs_path_canonical_path_and_base[0], False): cache_skips[frame_cache_key] = 1 if is_stepping and additional_info.pydev_original_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) and not _global_notify_skipped_step_in: notify_skipped_step_in_because_of_filters(py_db, frame) # A little gotcha, sometimes when we're stepping in we have to stop in a # return event showing the back frame as the current frame, so, we need # to check not only the current frame but the back frame too. back_frame = frame.f_back if back_frame is not None and pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE): if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) cache_skips[back_frame_cache_key] = 1 # if DEBUG: print('skipped: trace_dispatch (filtered out: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) return None if event == 'call' else NO_FTRACE else: # if DEBUG: print('skipped: trace_dispatch (filtered out: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) return None if event == 'call' else NO_FTRACE # if DEBUG: print('trace_dispatch', filename, frame.f_lineno, event, frame.f_code.co_name, file_type) # Just create PyDBFrame directly (removed support for Python versions < 2.5, which required keeping a weak # reference to the frame). ret = PyDBFrame( ( py_db, abs_path_canonical_path_and_base, additional_info, t, frame_skips_cache, frame_cache_key, ) ).trace_dispatch(frame, event, arg) if ret is None: # 1 means skipped because of filters. # 2 means skipped because no breakpoints were hit. cache_skips[frame_cache_key] = 2 return None if event == 'call' else NO_FTRACE # IFDEF CYTHON # frame.f_trace = SafeCallWrapper(ret) # Make sure we keep the returned tracer. # ELSE frame.f_trace = ret # Make sure we keep the returned tracer. # ENDIF return ret except SystemExit: return None if event == 'call' else NO_FTRACE except Exception: if py_db.pydb_disposed: return None if event == 'call' else NO_FTRACE # Don't log errors when we're shutting down. # Log it try: if pydev_log_exception is not None: # This can actually happen during the interpreter shutdown in Python 2.7 pydev_log_exception() except: # Error logging? We're really in the interpreter shutdown... # (https://github.com/fabioz/PyDev.Debugger/issues/8) pass return None if event == 'call' else NO_FTRACE finally: additional_info.is_tracing -= 1