a
    
”a¿;  ã                	   @   sL  d dl mZmZ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mZ d dlZzd dlZW n eyŽ   dZY n0 zd dlZW n.   zd dlZW n   d dlZY n0 Y n0 d dlZd dlZejZG dd„ dƒZdd	„ Z d
d„ Z!dd„ Z"dd„ Z#dd„ Z$dd„ Z%eƒ Z&dd„ Z'dd„ Z(dd„ Z)ddd„Z*dS )é    )Ú	get_frameÚ
IS_CPYTHONÚIS_64BIT_PROCESSÚ
IS_WINDOWSÚIS_LINUXÚIS_MACÚIS_PY2ÚDebugInfoHolderÚLOAD_NATIVE_LIB_FLAGÚENV_FALSE_LOWER_VALUESÚGlobalDebuggerHolderÚForkSafeLock)ÚthreadÚ	threading)Ú	pydev_logÚpydev_monkey)ÚosNc                   @   s    e Zd ZdZdZdZdZi ZdS )Ú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© r   r   úFlib/python3.9/site-packages/debugpy/_vendored/pydevd/pydevd_tracing.pyr      s
   r   c                  C   s6   t  ¡ } t ¡ }tj| d | d | d |d | ¡ S )Nr   r   é   )Úfile)ÚsysÚexc_infoÚStringIOÚ	tracebackÚprint_exceptionÚgetvalue)r"   Úsr   r   r   Úget_exception_traceback_str$   s    r(   c                 C   s>   d}t jr:t ¡ }| d¡ tj| t j|d || ¡  }|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'   r   r   r   Ú_get_stack_str+   s    
r/   c                 C   s–   t jr‚tƒ }|d ur‚|jd ur‚|jjj ¡ }| d¡s‚| d¡s‚ddt|jƒ  }|t j	vr‚dt j	|< t
j d|f ¡ t
j ¡  t jr’t  | ¡ d S )Nzthreading.pyzpydevd_tracing.pyz’
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   z%s
)r   r   r   Úf_backÚf_codeÚco_filenameÚlowerÚendswithr/   r   r!   Ústderrr+   Úflushr   )Útracing_funcr-   ÚfilenameÚmessager   r   r   Ú_internal_set_trace:   s    ýÿ


r:   c                 C   s<   | d ur$t | t ¡ gdddkr$d S tjp.tj}|| ƒ d S )NF)Úthread_identsÚcreate_dummy_threadr   )Úset_trace_to_threadsr   Ú	get_identr   r   r!   Úsettrace)r7   Ú	set_tracer   r   r   ÚSetTraceQ   s
    rA   c                   C   s   t jd u rtjt _tt_d S ©N)r   r   r!   r?   r:   r   r   r   r   Úreplace_sys_set_trace_funca   s    
rC   c                   C   s   t jd urt jt_d t _d S rB   )r   r   r!   r?   r   r   r   r   Úrestore_sys_set_trace_funcg   s    
rD   c               	   C   s~   zt jW S  ty   Y n0 tJ zt jW W  d   ƒ S  tyJ   Y n0 tƒ } | t _| W  d   ƒ S 1 sp0    Y  d S rB   )Ú_load_python_helper_libZ__lib__ÚAttributeErrorÚ_lockÚ _load_python_helper_lib_uncached)Úlibr   r   r   rE   p   s    rE   c            	         sB  t j t j t¡d¡} d}tr6t j dt j dd¡¡}|sTt 	¡ }|sTt
 d¡ d S trfd‰ d‰d‰n6trxd	‰ d‰d‰n$trŠd
‰ d‰d‰nt
 dtj¡ d S | ¡ dvrÈz‡ fdd„t  | ¡D ƒ}W n$   tjdkrät
 d| ¡ Y d S 0 d| ˆ  }d| ˆ  }d }||v r"t j | |¡}nxtrB||v rBt j | |¡}nXt|ƒdkrdt j | |d ¡}n6‡ ‡‡fdd„|D ƒ}t|ƒdkršt j | |d ¡}|d u r¸t
 d||| ¡ d S t
 d||¡ nXtrÔˆ}nˆ}tsätrêd}ntröd}nt
 dtj¡ d S t j | d||ˆ f ¡}t j |¡s>t
 d|¡ d S |S )NZpydevd_attach_to_processÚ ZPROCESSOR_ARCHITEW6432ZPROCESSOR_ARCHITECTUREz.platform.machine() did not return valid value.z.dllÚamd64Úx86z.soz.dylibÚx86_64z2Unable to set trace to all threads in platform: %s)rK   rL   rM   Zi386rL   c                    s$   g | ]}|  d ¡r| ˆ ¡r|‘qS )Úattach_)Ú
startswithr4   ©Ú.0Úname)Ú	extensionr   r   Ú
<listcomp>´   ó    z2get_python_helper_lib_filename.<locals>.<listcomp>r   zError listing dir: %srN   Zattach_linux_r   c                    s&   g | ]}|  ˆˆ  ˆˆ  f¡s|‘qS r   )r4   rP   ©rS   Z	suffix_32Z	suffix_64r   r   rT   É   rU   zMUnable to set trace to all threads in arch: %s (did not find a %s lib in %s).zUsing %s lib in arch: %s.z%s%s%szExpected: %s to exist.)r   ÚpathÚjoinÚdirnameÚ__file__r   ÚenvironÚgetÚplatformÚmachiner   Úinfor   r   r!   r3   Úlistdirr	   ÚDEBUG_TRACE_LEVELÚ	exceptionÚlenr   ÚexistsÚcritical)	ÚlibdirZarchÚfoundZexpected_nameZexpected_name_linuxr8   ZfilteredÚsuffixÚprefixr   rV   r   Úget_python_helper_lib_filename   s~    




þrj   c                  C   s˜   t r0td u s0tjd d… dks0ttdƒs0ttv r>t d¡ d S z0t	ƒ } | d u rTW d S tj
 | ¡}t d¡ |W S    tjdkrŒt d| ¡ Y d S 0 d S )Nr   )é   é
   Z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   Úctypesr!   Úversion_infoÚhasattrr
   r   r   r_   rj   ZpydllZLoadLibraryr	   ra   rb   )r8   rI   r   r   r   rH   ï   s$    ÿÿ


rH   Tc              
      s6  | d usJ ‚d}|d u r\t t ¡  ¡ ƒ}t ¡ D ]*}t|ddƒrN| |j¡ q0| 	|j¡ q0t
 ¡ }tj |¡}||v r¢t|ƒdkr¢t|ƒ}| |¡ | d|¡ |D ]ˆ‰|r@ˆtjvr@G ‡fdd„dtjƒ}|ƒ }tj|_ˆ|krî|}tj: |tjˆ< |tj|< |jˆkr t d¡ W d   ƒ n1 s60    Y  d}t
 ¡ ‰ˆ ¡  ‡ fdd	„‰ ‡ ‡fd
d„}	t t
¡}
|
|	dƒ ˆ ¡  d ‰tjpštj}tƒ }|d u r¼t d¡ d}q¦z4|  t! "|¡t! #|¡t! #| ¡t! $ˆ¡t! #d ¡¡}W n&   t%j&dkrt 'd¡ d}Y q¦0 |dkr¦t d|¡ |}q¦|S )Nr   Zpydev_do_not_traceFr   c                       s   e Zd Z‡ fdd„ZdS )z*set_trace_to_threads.<locals>._DummyThreadc                    s   t rˆ | _nˆ | _d S rB   )r   Z_Thread__identZ_ident)Úself©Úthread_identr   r   Ú
_set_ident-  s    z5set_trace_to_threads.<locals>._DummyThread._set_identN)r   r   r   rs   r   rq   r   r   Ú_DummyThread+  s   rt   zIpydevd: creation of _DummyThread with fixed thread ident did not succeed.c                    s   ˆ S rB   r   )r-   ZeventÚarg)Údummy_tracer   r   rv   O  s    z)set_trace_to_threads.<locals>.dummy_tracec                     s    t jp
tj} | ˆ ƒ ˆ ¡  d S rB   )r   r   r!   r?   Úrelease)r@   )rv   Úproceedr   r   Úincrease_tracing_countR  s    z4set_trace_to_threads.<locals>.increase_tracing_countr   zPUnable to load helper lib to set tracing to all threads (unsupported python vm).éÿÿÿÿz Error attaching debugger tracingz5Unable to set tracing for existing thread. Result: %s)(Úsetr!   Ú_current_framesÚkeysr   Ú	enumerateÚgetattrÚdiscardZidentÚaddr   r>   Z_activer\   rc   ÚlistÚremoveÚinsertrt   Ú	__class__Z_active_limbo_lockr   re   Úallocate_lockÚacquirer   Zget_original_start_new_threadr   r   r?   rE   r_   ZAttachDebuggerTracingrm   Zc_intZ	py_objectZc_uintr	   ra   rb   )r7   r;   r<   ZretÚtZ
curr_identZcurr_threadrt   Zshow_debug_infory   Ústart_new_threadZset_trace_funcrI   Úresultr   )rv   rx   rr   r   r=     sr    

	

*



û

r=   )NT)+Z_pydevd_bundle.pydevd_constantsr   r   r   r   r   r   r   r	   r
   r   r   r   Z _pydev_imps._pydev_saved_modulesr   r   Z_pydev_bundler   r   Úos.pathr   r]   rm   ÚImportErrorZ	cStringIOr#   Úior!   r$   r?   Z_original_settracer   r(   r/   r:   rA   rC   rD   rG   rE   rj   rH   r=   r   r   r   r   Ú<module>   s<   8
	n