set_trace(tracing_func) def replace_sys_set_trace_func(): if TracingFunctionHolder._original_tracing is None: TracingFunctionHolder._original_tracing = sys.settrace sys.settrace = _internal_set_trace def restore_sys_set_trace_func(): if TracingFunctionHolder._original_tracing is not None: sys.settrace = TracingFunctionHolder._original_tracing TracingFunctionHolder._original_tracing = None _lock = ForkSafeLock() def _load_python_helper_lib(): try: # If it's already loaded, just return it. return _load_python_helper_lib.__lib__ except AttributeError: pass with _lock: try: return _load_python_helper_lib.__lib__ except AttributeError: pass lib = _load_python_helper_lib_uncached()
thread, thread.ident, id(thread), current_frames, SUPPORT_GEVENT, ) return topmost_frame def __str__(self): return 'State:%s Stop:%s Cmd: %s Kill:%s' % ( self.pydev_state, self.pydev_step_stop, self.pydev_step_cmd, self.pydev_notify_kill) _set_additional_thread_info_lock = ForkSafeLock() def set_additional_thread_info(thread): try: additional_info = thread.additional_info if additional_info is None: raise AttributeError() except: with _set_additional_thread_info_lock: # If it's not there, set it within a lock to avoid any racing # conditions. additional_info = getattr(thread, 'additional_info', None) if additional_info is None: additional_info = PyDBAdditionalThreadInfo() thread.additional_info = additional_info
# Note: those are now inlined on cython. CMD_STEP_INTO = 107 CMD_STEP_INTO_MY_CODE = 144 CMD_STEP_RETURN = 109 CMD_STEP_RETURN_MY_CODE = 160 # ENDIF # Cache where we should keep that we completely skipped entering some context. # It needs to be invalidated when: # - Breakpoints are changed # It can be used when running regularly (without step over/step in/step return) global_cache_skips = {} global_cache_frame_skips = {} _global_notify_skipped_step_in = False _global_notify_skipped_step_in_lock = ForkSafeLock() def notify_skipped_step_in_because_of_filters(py_db, frame): global _global_notify_skipped_step_in with _global_notify_skipped_step_in_lock: if _global_notify_skipped_step_in: # Check with lock in place (callers should actually have checked # before without the lock in place due to performance). return _global_notify_skipped_step_in = True py_db.notify_skipped_step_in_because_of_filters(frame) # IFDEF CYTHON
def __init__(self): self._lock = ForkSafeLock() self._modules = {} self._next_id = partial(next, itertools.count(0))
class NetCommand(_BaseNetCommand): """ Commands received/sent over the network. Command can represent command received from the debugger, or one to be sent by daemon. """ next_seq = 0 # sequence numbers _showing_debug_info = 0 _show_debug_info_lock = ForkSafeLock(rlock=True) def __init__(self, cmd_id, seq, text, is_json=False): """ If sequence is 0, new sequence will be generated (otherwise, this was the response to a command from the client). """ protocol = get_protocol() self.id = cmd_id if seq == 0: NetCommand.next_seq += 2 seq = NetCommand.next_seq self.seq = seq if is_json: if hasattr(text, 'to_dict'): as_dict = text.to_dict(update_ids_to_dap=True) else: assert isinstance(text, dict) as_dict = text as_dict['pydevd_cmd_id'] = cmd_id as_dict['seq'] = seq self.as_dict = as_dict text = json.dumps(as_dict) assert isinstance(text, str) if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1: self._show_debug_info(cmd_id, seq, text) if is_json: msg = text else: if protocol not in (HTTP_PROTOCOL, HTTP_JSON_PROTOCOL): encoded = quote(to_string(text), '/<>_=" \t') msg = '%s\t%s\t%s\n' % (cmd_id, seq, encoded) else: msg = '%s\t%s\t%s' % (cmd_id, seq, text) if isinstance(msg, str): msg = msg.encode('utf-8') assert isinstance(msg, bytes) as_bytes = msg self._as_bytes = as_bytes def send(self, sock): as_bytes = self._as_bytes try: if get_protocol() in (HTTP_PROTOCOL, HTTP_JSON_PROTOCOL): sock.sendall(('Content-Length: %s\r\n\r\n' % len(as_bytes)).encode('ascii')) sock.sendall(as_bytes) except: if IS_JYTHON: # Ignore errors in sock.sendall in Jython (seems to be common for Jython to # give spurious exceptions at interpreter shutdown here). pass else: raise @classmethod def _show_debug_info(cls, cmd_id, seq, text): with cls._show_debug_info_lock: # Only one thread each time (rlock). if cls._showing_debug_info: # avoid recursing in the same thread (just printing could create # a new command when redirecting output). return cls._showing_debug_info += 1 try: out_message = 'sending cmd (%s) --> ' % (get_protocol(), ) out_message += "%20s" % ID_TO_MEANING.get( str(cmd_id), 'UNKNOWN') out_message += ' ' out_message += text.replace('\n', ' ') try: pydev_log.critical('%s\n', out_message) except: pass finally: cls._showing_debug_info -= 1