o
    i&;                     @   s  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Zd dlmZ 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e 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DebugInfoHolderLOAD_NATIVE_LIB_FLAGENV_FALSE_LOWER_VALUESForkSafeLock)thread	threading)	pydev_logpydev_monkeyN)StringIOc                   @   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   b/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd_tracing.pyr      s    r   c                  C   s4   t  } t }tj| d | d | d |d | S )Nr   r      )file)sysexc_infor   	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rWt }|d urW|jd urWtj|jjj	 d }|
dr1d|v r1| d u r0td d S n&|
dsWddt|j  }|t jvrWdt j|< tjd	|f  tj  t jrat |  d S d S )
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   z%s
)r   r   r   f_backospathsplitextf_codeco_filenamelowerendswithr   debugr,   r   r   stderrr(   flushr   )tracing_funcr*   filenamemessager   r   r   _internal_set_trace/   s.   



r>   c                 C   sB   | t _| 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   )	_last_tracing_func_thread_localr;   set_trace_to_threadsr   	get_identr   r   r   settrace)r;   	set_tracer   r   r   SetTraceS   s   rF   c                  C   s,   zt j} W n
 ty   Y d S w t|  d S N)rA   r;   AttributeErrorrF   )r;   r   r   r   reapply_settracee   s   
rI   c                   C   s    t jd u rtjt _tt_d S d S rG   )r   r   r   rD   r>   r   r   r   r   replace_sys_set_trace_funcn      

rJ   c                   C   s    t jd urt jt_d t _d S d S rG   )r   r   r   rD   r   r   r   r   restore_sys_set_trace_funct   rK   rL   c               	   C   s~   zt jW S  ty   Y nw t% zt jW W  d    S  ty%   Y nw t } | t _| W  d    S 1 s8w   Y  d S rG   )_load_python_helper_lib__lib__rH   _lock _load_python_helper_lib_uncached)libr   r   r   rM   }   s    $rM   c            	         s*  t jt jtd} d}trt jdt jdd}|s*t	 }|s*t
d d S tr3d ddntr<d	 ddntrEd
 ddn	t
dtj d S | dvrz fddt | D }W n   tjdkrqt
d|  Y d S d|   }d|   }d }||v rt j| |}n8tr||v rt j| |}n*t|dkrt j| |d }n fdd|D }t|dkrt j| |d }|d u rt
d|||  d S t
d|| n(tr}n}tstrd}ntrd}n	t
dtj d S t j| d|| f }t j|st
d| d S |S )Npydevd_attach_to_process PROCESSOR_ARCHITEW6432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)rV   rW   rX   i386rW   c                    s$   g | ]}| d r| r|qS )attach_)
startswithr7   .0name)	extensionr   r   
<listcomp>   s   $ z2get_python_helper_lib_filename.<locals>.<listcomp>r   zError listing dir: %srZ   attach_linux_r   c                    s&   g | ]}|     fs|qS r   )r7   r\   r_   	suffix_32	suffix_64r   r   r`      s   & 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.)r1   r2   joindirname__file__r   environgetplatformmachiner   infor   r   r   r6   listdirr   DEBUG_TRACE_LEVEL	exceptionlenr   existscritical)	libdirarchfoundexpected_nameexpected_name_linuxr<   filteredsuffixprefixr   rb   r   get_python_helper_lib_filename   s~   


r{   c                  C   s   t rtjd d dksttdsttv rtd d S zt } | d u r&W d S t	j
| }td |W S    tjdkrBtd|  Y d S )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   rl   r{   ctypespydllLoadLibraryr   rn   ro   )r<   rQ   r   r   r   rP      s"   


rP   Tc              
      s&  | d usJ d}|d u r.t t  }t D ]}t|ddr'||j q|	|j qt
 }tj|}||v rQt|dkrQt|}|| |d| |D ]|rtjvrG fdddtj}| }tj|_|krt|}tj |tj< |tj|< |jkrtd W d    n1 sw   Y  d}t
    fdd	  fd
d}	tt
}
|
|	d   d tjptj}t }|d u rtd d}qSz| t!"|t!#|t!#| t!$t!#d }W n   t%j&dkrt'd d}Y qS|dkrtd| |}qS|S )Nr   pydev_do_not_traceFr   c                       s   e Zd Z fddZdS )z*set_trace_to_threads.<locals>._DummyThreadc                    s
    | _ d S rG   )_ident)selfthread_identr   r   
_set_ident:  s   
z5set_trace_to_threads.<locals>._DummyThread._set_identN)r   r   r   r   r   r   r   r   _DummyThread8  s    r   zIpydevd: creation of _DummyThread with fixed thread ident did not succeed.c                    s    S rG   r   )r*   eventarg)dummy_tracer   r   r   Y  s   z)set_trace_to_threads.<locals>.dummy_tracec                     s    t jptj} |     d S rG   )r   r   r   rD   release)rE   )r   proceedr   r   increase_tracing_count\  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discardidentaddr   rC   _activeri   rp   listremoveinsertr   	__class___active_limbo_lockr   rr   allocate_lockacquirer   get_original_start_new_threadr   r   rD   rM   rl   AttachDebuggerTracingr   c_int	py_objectc_uintr   rn   ro   )r;   r?   r@   rett
curr_identcurr_threadr   show_debug_infor   start_new_threadset_trace_funcrQ   resultr   )r   r   r   r   rB     sx   











rB   )NT)*_pydevd_bundle.pydevd_constantsr   r   r   r   r   r   r   r	   r
   r   "_pydev_bundle._pydev_saved_modulesr   r   _pydev_bundler   r   os.pathr1   rj   r   ior   r   r!   rD   _original_settracer   r%   r,   r>   localrA   rF   rI   rJ   rL   rO   rM   r{   rP   rB   r   r   r   r   <module>   s0   0 	!	n