
    Ge-                         d dl mZmZmZmZmZmZmZmZm	Z	m
Z
 d dlmZmZ d dlmZmZ d dlZd dlZd dlmZ d dlZd dlZej0                  Z G d d      Zd Zd	 Zd
 Z ej<                         Zd Z d Z!d Z"d Z# e
       Z$d Z%d Z&d Z'ddZ(y)    )
	get_frame
IS_CPYTHONIS_64BIT_PROCESS
IS_WINDOWSIS_LINUXIS_MACDebugInfoHolderLOAD_NATIVE_LIB_FLAGENV_FALSE_LOWER_VALUESForkSafeLock)thread	threading)	pydev_logpydev_monkeyN)StringIOc                        e Zd ZdZdZdZdZi Zy)TracingFunctionHolderzhThis class exists just to keep some variables (so that we don't keep them in the global namespace).
    NT   )__name__
__module____qualname____doc___original_tracing_warn_traceback_limit_warnings_shown     0/usr/lib/python3/dist-packages/pydevd_tracing.pyr   r      s    EOr   r   c                      t        j                         } t               }t        j                  | d   | d   | d   |       |j                         S )Nr   r      )file)sysexc_infor   	tracebackprint_exceptiongetvalue)r$   ss     r   get_exception_traceback_strr)      s@    ||~H
Ahqk8A;!L::<r   c                     d}t         j                  rTt               }|j                  d       t	        j
                  | t         j                  |       ||j                         z   }|S )Nz
If this is needed, please check: 
http://pydev.blogspot.com/2007/06/why-cant-pydev-debugger-work-with.html
to see how to restore the debug tracing back correctly.
zCall Location:
)flimitr"   )r   r   r   writer%   print_stackr'   )framemsgr(   s      r   _get_stack_strr1      sX    HC --J	"#-B-S-SZ[\AJJL Jr   c                    t         j                  r&t               }||j                  t        j
                  j                  |j                  j                  j                  j                               d   }|j                  d      rd|v r| t        j                  d       y |j                  d      sddt        |j                        z  z   }|t         j                  vrSdt         j                  |<   t        j                   j#                  |d	       t        j                   j%                          t         j&                  rt         j'                  |        y y )
Nr   
threadpoolgeventz6Disabled internal sys.settrace from gevent threadpool.)r   pydevd_tracingz
PYDEV DEBUGGER WARNING:
sys.settrace() should not be used when the debugger is being used.
This may cause the debugger to stop working correctly.z%sr   
)r   r   r   f_backospathsplitextf_codeco_filenamelowerendswithr   debugr1   r   r#   stderrr-   flushr   )tracing_funcr/   filenamemessages       r   _internal_set_tracerE   .   s   ""!9ww''(;(;(G(G(M(M(OPQRSH  .8x3G'OO$\]&&K ~ell334  "7"G"GGEF)99'BJJ$$w%89JJ$$&..//= /r   c                     | t         _        | %t        | t        j                         gd      dk(  ry t
        j                  xs t        j                  } ||        y )NF)thread_identscreate_dummy_threadr   )	_last_tracing_func_thread_localrB   set_trace_to_threadsr   	get_identr   r   r#   settrace)rB   	set_traces     r   SetTracerN   R   sS    3?#0V=M=M=O<Pfklpqq  &77G3<<Ilr   c                  Z    	 t         j                  } t        |        y # t        $ r Y y w xY wN)rI   rB   rN   AttributeError)rB   s    r   reapply_settracerR   d   s0    6CC 	  s    	**c                  v    t         j                  )t        j                  t         _        t        t        _        y y rP   )r   r   r#   rL   rE   r   r   r   replace_sys_set_trace_funcrT   m   s'    ..625,,/* 7r   c                  n    t         j                  %t         j                  t        _        d t         _        y y rP   )r   r   r#   rL   r   r   r   restore_sys_set_trace_funcrV   s   s)    ..:,>>26/ ;r   c                      	 t         j                  S # t        $ r Y nw xY wt        5  	 t         j                  cd d d        S # t        $ r Y nw xY wt	               } | t         _        | cd d d        S # 1 sw Y   y xY wrP   )_load_python_helper_lib__lib__rQ   _lock _load_python_helper_lib_uncached)libs    r   rX   rX   |   s    &... 	 	*22   		 /0*-'  s4    	A1A	AA1AA11A:c                     t         j                  j                  t         j                  j                  t              d      } t
        st        dt        j                         y d}t         j                  j                  | |      }t        j                  d|       t         j                  j                  |      st        j                  d|       y |S )Npydevd_attach_to_processz+Unable to attach to process in platform: %sz	attach.sozUsing %s lib.zExpected: %s to exist.)r8   r9   joindirname__file__r   printr#   platformr   infoexistscritical)libdirlibnamerC   s      r   get_python_helper_lib_filenameri      s     WW\\"''//(35OPF ;S\\JGww||FG,HNN?H-77>>(#3X>Or   c                     t         r2t        j                  d d dkD  st        t        d      st        t
        v rt        j                  d       y 	 t               } | y t        j                  j                  |       }t        j                  d       |S #  t        j                  dk\  rt        j                  d        Y y xY w)Nr!   )      gettotalrefcountz4Helper lib to set tracing to all threads not loaded.z=Successfully Loaded helper lib to set tracing to all threads.r   zError loading: %s)r   r#   version_infohasattrr
   r   r   rd   ri   ctypespydllLoadLibraryr	   DEBUG_TRACE_LEVEL	exception)rC   r\   s     r   r[   r[      s    #**2A.8s./3GKa3aMN13ll&&x0VW
,,1  3X>s   B 5B +C c           
         | J d}|t        t        j                         j                               }t	        j
                         D ]F  }t        |dd      r|j                  |j                         ,|j                  |j                         H t        j                         }t        j                  j                  |      }||v r<t        |      dk7  r.t        |      }|j!                  |       |j#                  d|       |D ]  |rt        j                  vr G fddt        j$                        } |       }t        j$                  |_        |k(  r|}t        j(                  5  |t        j                  <   |t        j                  |<   |j                  k7  rt+        j,                  d       d d d        d}t        j.                         j1                          fdfd	}	t3        j4                  t              }
 |
|	d
       j1                          d t6        j8                  xs t        j:                  }t=               }|t+        j>                  d       d}e	 |jA                  tC        jD                  |      tC        jF                  |      tC        jF                  |       tC        jH                        tC        jF                  d             }|dk7  st+        j>                  d|       |} |S # 1 sw Y   OxY w#  tJ        jL                  dk\  rt+        jN                  d       d}Y :xY w)Nr   pydev_do_not_traceFr   c                       e Zd Z fdZy)*set_trace_to_threads.<locals>._DummyThreadc                     | _         y rP   )_ident)selfthread_idents    r   
_set_identz5set_trace_to_threads.<locals>._DummyThread._set_ident   s
    &2r   N)r   r   r   r}   )r|   s   r   _DummyThreadrx      s    3r   r~   zIpydevd: creation of _DummyThread with fixed thread ident did not succeed.c                     S rP   r   )r/   eventargdummy_traces      r   r   z)set_trace_to_threads.<locals>.dummy_trace  s	    r   c                  z    t         j                  xs t        j                  }  |        j	                          y rP   )r   r   r#   rL   release)rM   r   proceeds    r   increase_tracing_countz4set_trace_to_threads.<locals>.increase_tracing_count  s)    -??O3<<Ik"OOr   r   zPUnable to load helper lib to set tracing to all threads (unsupported python vm).z5Unable to set tracing for existing thread. Result: %sz Error attaching debugger tracing)(setr#   _current_frameskeysr   	enumerategetattrdiscardidentaddr   rK   _activegetlenlistremoveinsertr~   	__class___active_limbo_lockr   rf   allocate_lockacquirer   get_original_start_new_threadr   r   rL   rX   rd   AttachDebuggerTracingrp   c_int	py_objectc_uintr	   rs   rt   )rB   rG   rH   rett
curr_identcurr_threadr~   show_debug_infor   start_new_threadset_trace_funcr\   resultr   r   r|   s                 @@@r   rJ   rJ      s   ###
C C//16689$$& 	+A q.6%%agg.!!!''*	+ !!#J##''
3K]"s='9Q'> ]+Z(Q
+% L! 9#4#4439#9#9 3 !N'44:-"#K11 	x 78I%%l34?I%%j1ww,.!**+vw	x  &&(		
 (EEfM/4 /@@PCLL%';NNmnC!22LL1$$^4$$\2MM,/$$T* Q;NN#Z\bc CYL!\ Jw	x 	xb"449''(JKs   /AL/A4LL	,M)NT))_pydevd_bundle.pydevd_constantsr   r   r   r   r   r   r	   r
   r   r   "_pydev_bundle._pydev_saved_modulesr   r   _pydev_bundler   r   os.pathr8   rp   ior   r#   r%   rL   _original_settracer   r)   r1   rE   localrI   rN   rR   rT   rV   rZ   rX   ri   r[   rJ   r   r   r   <module>r      s   ) ) ) A 1    
 \\  >B #2)//"3 $+7 	"6,nr   