
    "ev                         d dl mZ d dlmZ d dlmZ d dlZd dlmZm	Z	m
Z
 d dlmZ d dlZd dlmZ d dlZd dlmZ er	d dlmc mZ  G d	 d
ej.                        Zd Zd Zdad Zd Zy)    )	threading)_pydev_saved_modules)notify_about_gevent_if_neededN)	IS_JYTHONIS_IRONPYTHON,PYDEVD_APPLY_PATCHING_TO_HIDE_PYDEVD_THREADS)	exception)	pydev_log)iter_instructionsc                   <    e Zd ZddZed        Zd Zd Zd Zd Z	y)	PyDBDaemonThreadNc                     t         j                  j                  |        t                t	        j
                  |      | _        d| _        t        |        || _	        y)z
        :param target_and_args:
            tuple(func, args, kwargs) if this should be a function and args to run.
            -- Note: use through run_as_pydevd_daemon_thread().
        FN)
r   Thread__init__r   weakrefref_py_db_kill_receivedmark_as_pydevd_daemon_thread_target_and_args)selfpy_dbtarget_and_argss      E/usr/lib/python3/dist-packages/_pydevd_bundle/pydevd_daemon_thread.pyr   zPyDBDaemonThread.__init__   sF     	!!$'%'kk%(#$T* /    c                 "    | j                         S N)r   r   s    r   r   zPyDBDaemonThread.py_db    s    {{}r   c                    | j                   j                  }d|| <   	 	 t        r_t        t	        j
                         t        j                        s3t        j                         }t        j                  j                  |       | j                          | j                          || = y #  t        t        
t                Y xY w# || = w xY w)N   )r   created_pydb_daemon_threadsr   
isinstancer   current_thread_MainThreadJyCorePySystemStatePysetSystemState_stop_trace_on_runsyspydev_log_exception)r   created_pydb_daemonsss      r   runzPyDBDaemonThread.run$   s    "jjDD$%D!	**Z	0H0H0JILaLa%b  --/BII,,R0  "
 $D)	*?':'F')#D)s   BB' 'C?C C	c                 |    | j                   | j                   \  }}} ||i | y t        d| j                  z        )NzShould be reimplemented by: %s)r   NotImplementedError	__class__)r   targetargskwargss       r   r*   zPyDBDaemonThread._on_run8   sB      ,#'#8#8 FD&D#F#%&F&WXXr   c                 l    | j                   s(t        j                  d| j                         d| _         y y )Nz%s received kill signalT)r   r
   debugnamer   s    r   do_kill_pydev_threadz%PyDBDaemonThread.do_kill_pydev_thread?   s+    ""OO5tyyA"&D #r   c                 H    | j                   rt        j                  d        y y r   )pydev_do_not_tracepydevd_tracingSetTracer   s    r   r)   zPyDBDaemonThread._stop_traceD   s    ""##D) #r   r   )
__name__
__module____qualname__r   propertyr   r/   r*   r9   r)    r   r   r   r      s0    0  *(Y'
*r   r   c                     t               }t        | j                        D ],  }|j                  dv s|j	                  |j
                         . |S )N)LOAD_GLOBAL	LOAD_ATTRLOAD_METHOD)setr   __code__opnameaddargrepr)funcfound_load_namesinstructions      r   _collect_load_namesrO   I   sM    u(7 6!LL  !4!456 r   c                  
   t        t        j                        } d}| h dh dh dfv rt        j                  d       d }n=| t        d      k(  rt        j                  d       d	 }nt        j                  d
|        |d }|t        _        |j                  t        j                  _	        d }|j                  t        j                  _	        t        t        d      r#d }|j                  t        j                  _	        yyy)z
    Patches the needed functions on the `threading` module so that the pydevd threads are hidden.

    Note that we patch the functions __code__ to avoid issues if some code had already imported those
    variables prior to the patching.
    N>   list_limbovalues_active_active_limbo_lock>   rR   rS   rT   rU   NULL + list>   NULL|self + valuesrR   rT   rU   rV   z7Applying patching to hide pydevd threads (Py3 version).c                      t         5  t        t        j                               t        t        j                               z   } d d d         D cg c]  }t        |dd      r| c}S # 1 sw Y   'xY wc c}w Nis_pydev_daemon_threadF)rU   rQ   rT   rS   rR   getattrretts     r   new_threading_enumeratezH_patch_threading_to_hide_pydevd_threads.<locals>.new_threading_enumerated   sc    # E7>>+,tFMMO/DDE  #V!'!5Mu*UAVVE E Ws   <A)A5"A5)A2)rU   rR   rT   rS   z7Applying patching to hide pydevd threads (Py2 version).c                      t         5  t        j                         t        j                         z   } d d d         D cg c]  }t	        |dd      r| c}S # 1 sw Y   'xY wc c}w rY   )rU   rT   rS   rR   r[   r\   s     r   r_   zH_patch_threading_to_hide_pydevd_threads.<locals>.new_threading_enumeratem   sU    # 9nn&89  #V!'!5Mu*UAVV9 9 Ws   *AA#A#A zEUnable to hide pydevd threads. Found names in threading.enumerate: %sc                      t         j                  5  t        t         j                  j	                               t        t         j
                  j	                               z   cd d d        S # 1 sw Y   y xY wr   )r   rU   rQ   rT   rS   rR   rB   r   r    pydevd_saved_threading_enumeratezQ_patch_threading_to_hide_pydevd_threads.<locals>.pydevd_saved_threading_enumeratex   sT    -- ZI--4467$y?O?O?V?V?X:YYZ Z Zs   AA**A3c                  (    t        t                     S r   )len	enumeraterB   r   r   new_active_countzA_patch_threading_to_hide_pydevd_threads.<locals>.new_active_count   s     y{##r   _pickSomeNonDaemonThreadc                      t         5  t        t        j                               t        t        j                               z   } d d d         D ]#  }|j
                  r|j                         s!|c S  y # 1 sw Y   2xY wr   )rU   rQ   rT   rS   rR   daemonis_alive)threadsr^   s     r   new_pick_some_non_daemon_threadzP_patch_threading_to_hide_pydevd_threads.<locals>.new_pick_some_non_daemon_thread   si    ' M"7>>#34tFMMO7LLGM ! !A88

 ! M Ms   <A44A=)rO   r   re   r
   r7   rG   infor   rb   rH   active_counthasattrrg   )rM   r_   rb   rf   rl   s        r   '_patch_threading_to_hide_pydevd_threadsrp   Q   s     +9+>+>? #ELX
 

 	QR	W 
S!VW	WQR	W 	^`pq*	Z Aa='>'G'G	$	$
 +;*C*C	' 989 ;Z:b:bI..7 :; +r   Fc                     t         st        st        rt        sda	 t	                d| _        d| _        d| _	        y #  t        j                  d       Y /xY w)NTz/Error applying patching to hide pydevd threads.)
r   r   r   )_patched_threading_to_hide_pydevd_threadsrp   r
   r	   r;   rZ   ri   )threads    r   r   r      sQ    ]/[8 9=5W79 !%F$(F!FMW##$UVs	   
< Ac                 n    t        | |||f      }|j                  d|_        |j                          |S )zS
    Runs a function as a pydevd daemon thread (without any tracing in place).
    )r   z (pydevd daemon thread))r   r>   r8   start)r   rL   r4   r5   r^   s        r   run_as_pydevd_daemon_threadrv      s3     	tV0DEA,0MM;AFGGIHr   )"_pydev_bundle._pydev_saved_modulesr   _pydev_bundler   _pydevd_bundle.pydevd_utilsr   r   _pydevd_bundle.pydevd_constantsr   r   r   _pydev_bundle.pydev_logr	   r,   r+   r
   r<   +_pydevd_bundle.pydevd_collect_bytecode_infor   org.python.corepythoncorer%   r   r   rO   rp   rr   r   rv   rB   r   r   <module>r      se    8 . E 1 1 D 
 #  I$$5*y'' 5*pNcb -2 ),r   