a
    zez                     @   s   d dl Z d dlZd dlZd dlmZmZmZ g dZeeB eB ZG dd de	Z
G dd dZdd	 ZG d
d dZdd Zdd ZG dd deZdd Zdd Zdd ZdS )    N)CO_GENERATORCO_COROUTINECO_ASYNC_GENERATOR)BdbQuitBdb
Breakpointc                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r   r   /usr/lib/python3.9/bdb.pyr      s   r   c                   @   sl  e Zd ZdYddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# ZdZd%d&Zd[d'd(Zd)d* Zd+d, Zd-d. Zd\d/d0Zd1d2 Zd3d4 Zd]d6d7Zd8d9 Zd:d; Zd<d= Zd>d? Z d@dA Z!dBdC Z"dDdE Z#dFdG Z$dHdI Z%dJdK Z&dLdM Z'd^dOdPZ(d_dQdRZ)d`dSdTZ*dUdV Z+dWdX Z,dS )ar   Nc                 C   s(   |rt |nd | _i | _i | _d | _d S N)setskipbreaksfncacheframe_returning)selfr   r   r   r   __init__   s    zBdb.__init__c                 C   sR   |d|dd  d kr|S | j |}|sNtj|}tj|}|| j |< |S )N<   >)r   getospathabspathnormcase)r   filenamecanonicr   r   r   r   %   s    
zBdb.canonicc                 C   s&   dd l }|  d | _| d d  d S )Nr   )	linecache
checkcachebotframe_set_stopinfo)r   r    r   r   r   reset6   s    z	Bdb.resetc                 C   s   | j r
d S |dkr| |S |dkr0| ||S |dkrD| ||S |dkrX| ||S |dkrf| jS |dkrt| jS |dkr| jS tdt| | jS )	Nlinecallreturn	exceptionZc_callZc_exceptionZc_returnz*bdb.Bdb.dispatch: unknown debugging event:)quittingdispatch_linedispatch_calldispatch_returndispatch_exceptiontrace_dispatchprintrepr)r   frameeventargr   r   r   r.   =   s$    
zBdb.trace_dispatchc                 C   s.   |  |s| |r(| | | jr(t| jS r   )	stop_here
break_here	user_liner)   r   r.   r   r1   r   r   r   r*   h   s    

zBdb.dispatch_linec                 C   sd   | j d u r|j| _ | jS | |s0| |s0d S | jrH|jjt@ rH| jS | 	|| | j
r^t| jS r   )r"   f_backr.   r4   break_anywhere	stopframef_codeco_flagsGENERATOR_AND_COROUTINE_FLAGS	user_callr)   r   r   r1   r3   r   r   r   r+   t   s    

zBdb.dispatch_callc                 C   s   |  |s|| jkr|| jr,|jjt@ r,| jS z|| _| || W d | _nd | _0 | j	r\t
| j|u r|| jdkr|| d d  | jS Nr   )r4   returnframer:   r;   r<   r=   r.   r   user_returnr)   r   
stoplinenor#   r?   r   r   r   r,      s    
zBdb.dispatch_returnc                 C   s   |  |rF|jjt@ r.|d tu r.|d d u s| || | jrtnD| jr|| jur| jjjt@ r|d tt	fv r| || | jrt| j
S )Nr      )r4   r;   r<   r=   StopIterationuser_exceptionr)   r   r:   GeneratorExitr.   r?   r   r   r   r-      s     



zBdb.dispatch_exceptionc                 C   s.   |d u rdS | j D ]}t||r dS qdS NFT)r   fnmatch)r   module_namepatternr   r   r   is_skipped_module   s    
zBdb.is_skipped_modulec                 C   sN   | j r| |jdrdS || ju r@| jdkr4dS |j| jkS | jsJdS dS )Nr   Fr   T)r   rL   	f_globalsr   r:   rC   f_linenor7   r   r   r   r4      s    

zBdb.stop_herec                 C   s   |  |jj}|| jvrdS |j}|| j| vrJ|jj}|| j| vrJdS t|||\}}|r|j| _|r|j	r| 
t|j dS dS d S rH   )r   r;   co_filenamer   rN   co_firstlineno	effectivenumberZ	currentbp	temporarydo_clearstr)r   r1   r   linenobpflagr   r   r   r5      s    

zBdb.break_herec                 C   s   t dd S )Nz)subclass of bdb must implement do_clear())NotImplementedError)r   r3   r   r   r   rT      s    zBdb.do_clearc                 C   s   |  |jj| jv S r   )r   r;   rO   r   r7   r   r   r   r9      s    zBdb.break_anywherec                 C   s   d S r   r   )r   r1   Zargument_listr   r   r   r>     s    zBdb.user_callc                 C   s   d S r   r   r7   r   r   r   r6     s    zBdb.user_linec                 C   s   d S r   r   )r   r1   Zreturn_valuer   r   r   rB   	  s    zBdb.user_returnc                 C   s   d S r   r   )r   r1   exc_infor   r   r   rF     s    zBdb.user_exceptionr   c                 C   s   || _ || _d| _|| _d S NF)r:   rA   r)   rC   )r   r:   rA   rC   r   r   r   r#     s    zBdb._set_stopinfoc                 C   s$   |d u r|j d }| ||| d S )Nr   )rN   r#   )r   r1   rV   r   r   r   	set_until"  s    
zBdb.set_untilc                 C   s0   | j r | j j}|r |js | j|_| d d  d S r   )r   r8   f_tracer.   r#   )r   Zcaller_framer   r   r   set_step*  s
    
zBdb.set_stepc                 C   s   |  |d  d S r   )r#   r7   r   r   r   set_next6  s    zBdb.set_nextc                 C   s.   |j jt@ r| |d d n| |j| d S r@   )r;   r<   r=   r#   r8   r7   r   r   r   
set_return:  s    zBdb.set_returnc                 C   sL   |d u rt  j}|   |r4| j|_|| _|j}q|   t | j d S r   )	sys	_getframer8   r$   r.   r]   r"   r^   settracer7   r   r   r   	set_traceA  s    
zBdb.set_tracec                 C   sH   |  | jd d | jsDtd  t j}|rD|| jurD|`|j}q*d S r@   )r#   r"   r   ra   rc   rb   r8   r]   r7   r   r   r   set_continueP  s    

zBdb.set_continuec                 C   s"   | j | _d | _d| _td  d S NT)r"   r:   rA   r)   ra   rc   r   r   r   r   set_quit_  s    zBdb.set_quitFc           
      C   sb   |  |}dd l}|||}|s.d||f S | j|g }||vrN|| t|||||}	d S )Nr   zLine %s:%d does not exist)r   r    getliner   
setdefaultappendr   )
r   r   rV   rS   condfuncnamer    r%   listrW   r   r   r   	set_breakp  s    

zBdb.set_breakc                 C   s4   ||ft jvr| j| | | j| s0| j|= d S r   )r   bplistr   remover   r   rV   r   r   r   _prune_breaks  s    
zBdb._prune_breaksc                 C   sj   |  |}|| jvrd| S || j| vr6d||f S tj||f d d  D ]}|  qL| || d S )NThere are no breakpoints in %szThere is no breakpoint at %s:%d)r   r   r   rp   deleteMers   )r   r   rV   rW   r   r   r   clear_break  s    


zBdb.clear_breakc              
   C   sX   z|  |}W n, ty: } zt|W  Y d }~S d }~0 0 |  | |j|j d S r   )get_bpbynumber
ValueErrorrU   ru   rs   filer%   )r   r3   rW   errr   r   r   clear_bpbynumber  s    zBdb.clear_bpbynumberc                 C   sX   |  |}|| jvrd| S | j| D ]$}tj||f }|D ]}|  q<q&| j|= d S )Nrt   )r   r   r   rp   ru   )r   r   r%   ZblistrW   r   r   r   clear_all_file_breaks  s    

zBdb.clear_all_file_breaksc                 C   s,   | j s
dS tjD ]}|r|  qi | _ d S )NzThere are no breakpoints)r   r   
bpbynumberru   )r   rW   r   r   r   clear_all_breaks  s    

zBdb.clear_all_breaksc                 C   s   |st dzt|}W n  t y8   t d| d Y n0 ztj| }W n  tyh   t d| d Y n0 |d u r~t d| |S )NzBreakpoint number expectedz Non-numeric breakpoint number %sz!Breakpoint number %d out of rangezBreakpoint %d already deleted)rx   intr   r}   
IndexError)r   r3   rR   rW   r   r   r   rw     s    zBdb.get_bpbynumberc                 C   s"   |  |}|| jv o || j| v S r   r   r   rr   r   r   r   	get_break  s    

zBdb.get_breakc                 C   s4   |  |}|| jv r0|| j| v r0tj||f p2g S r   )r   r   r   rp   rr   r   r   r   
get_breaks  s    

zBdb.get_breaksc                 C   s&   |  |}|| jv r| j| S g S d S r   r   )r   r   r   r   r   get_file_breaks  s    


zBdb.get_file_breaksc                 C   s   | j S r   )r   rg   r   r   r   get_all_breaks  s    zBdb.get_all_breaksc                 C   s   g }|r|j |u r|j}|d urD|||jf || ju r<qD|j}q|  tdt|d }|d ur||j |j	f |j}q^|d u rtdt|d }||fS )Nr   r   )
tb_frametb_nextrk   rN   r"   r8   reversemaxlen	tb_lineno)r   ftstackir   r   r   	get_stack  s     
zBdb.get_stack: c                 C   s   dd l }dd l}|\}}| |jj}d||f }|jjrH||jj7 }n|d7 }|d7 }d|jv r|jd }	|d7 }|||	7 }||||j	}
|
r|||

  7 }|S )Nr   z%s(%r)z<lambda>z()Z
__return__z->)r    reprlibr   r;   rO   co_namef_localsr0   ri   rM   strip)r   Zframe_linenoZlprefixr    r   r1   rV   r   srvr%   r   r   r   format_stack_entry  s     	

zBdb.format_stack_entryc              	   C   s   |d u rdd l }|j}|d u r"|}|   t|tr@t|dd}t| j z8zt	||| W n t
yp   Y n0 W d| _td  nd| _td  0 d S )Nr   z<string>execT)__main____dict__r$   
isinstancerU   compilera   rc   r.   r   r   r)   )r   cmdglobalslocalsr   r   r   r   run5  s"    
zBdb.runc              	   C   s   |d u rdd l }|j}|d u r"|}|   t| j zHz t|||W W d| _td  S  tyj   Y n0 W d| _td  nd| _td  0 d S )Nr   T)	r   r   r$   ra   rc   r.   evalr)   r   )r   exprr   r   r   r   r   r   runevalK  s$    
zBdb.runevalc                 C   s   |  ||| d S r   )r   )r   r   r   r   r   r   r   runctx_  s    z
Bdb.runctxc             	   O   sj   |    t| j d }z:z||i |}W n ty>   Y n0 W d| _td  nd| _td  0 |S rf   )r$   ra   rc   r.   r   r)   )r   funcargskwdsresr   r   r   runcallf  s    zBdb.runcall)N)r   )N)N)FNN)r   )NN)NN)-r   r	   r
   r   r   r$   r.   r*   r+   r,   r-   rL   r4   r5   rT   r9   r>   r6   rB   rF   r#   r\   r^   r_   r`   rd   re   rh   ro   rs   rv   r{   r|   r~   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      sX   
+	


  




r   c                   C   s   t    d S r   )r   rd   r   r   r   r   rd   x  s    rd   c                   @   sV   e Zd ZdZi ZdgZdddZdd Zdd	 Zd
d Z	dddZ
dd Zdd ZdS )r   r   NFc                 C   s   || _ d | _|| _|| _|| _|| _d| _d| _d| _t	j
| _t	 j
d7  _
| j|  ||f| jv r|| j||f |  n| g| j||f< d S )NTr   r   )rm   func_first_executable_linery   r%   rS   rl   enabledignorehitsr   nextrR   r}   rk   rp   )r   ry   r%   rS   rl   rm   r   r   r   r     s    zBreakpoint.__init__c                 C   s>   | j | jf}d | j| j< | j| |  | j| s:| j|= d S r   )ry   r%   r}   rR   rp   rq   )r   indexr   r   r   ru     s
    
zBreakpoint.deleteMec                 C   s
   d| _ d S rf   r   rg   r   r   r   enable  s    zBreakpoint.enablec                 C   s
   d| _ d S r[   r   rg   r   r   r   disable  s    zBreakpoint.disablec                 C   s"   |d u rt j}t|  |d d S )N)ry   )ra   stdoutr/   bpformat)r   outr   r   r   bpprint  s    zBreakpoint.bpprintc                 C   s   | j rd}nd}| jr |d }n|d }d| j|| j| jf }| jrT|d| jf 7 }| jrj|d| jf 7 }| jr| jdkrd	}nd
}|d| j|f 7 }|S )Nzdel  zkeep zyes  zno   z%-4dbreakpoint   %s at %s:%dz
	stop only if %sz
	ignore next %d hitsr   r    z"
	breakpoint already hit %d time%s)rS   r   rR   ry   r%   rl   r   r   )r   Zdispretssr   r   r   r     s&    

zBreakpoint.bpformatc                 C   s   d| j | j| jf S )Nzbreakpoint %s at %s:%s)rR   ry   r%   rg   r   r   r   __str__  s    zBreakpoint.__str__)FNN)N)r   r	   r
   r   rp   r}   r   ru   r   r   r   r   r   r   r   r   r   r   }  s   


r   c                 C   sN   | j s| j|jkrdS dS |jj| j kr,dS | js:|j| _| j|jkrJdS dS rH   )rm   r%   rN   r;   r   r   )br1   r   r   r   checkfuncname  s    r   c                 C   s   t j| |f }|D ]}|jsqt||s*q| jd7  _|jsh|jdkrZ| jd8  _qq|df  S qzBt|j|j|j	}|r|jdkr| jd8  _n|dfW   S W q   |df Y   S 0 qdS )Nr   r   TF)NN)
r   rp   r   r   r   rl   r   r   rM   r   )ry   r%   r1   Z	possiblesr   valr   r   r   rQ     s*    


rQ   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
Tdbc                 C   s    |j j}|sd}td|| d S )N???z+++ call)r;   r   r/   )r   r1   r   namer   r   r   r>   D  s    zTdb.user_callc                 C   sT   dd l }|jj}|sd}| |jj}|||j|j}td||j|d|	  d S )Nr   r   z+++:)
r    r;   r   r   rO   ri   rN   rM   r/   r   )r   r1   r    r   fnr%   r   r   r   r6   H  s    zTdb.user_linec                 C   s   t d| d S )Nz
+++ returnr/   )r   r1   Zretvalr   r   r   rB   O  s    zTdb.user_returnc                 C   s   t d| |   d S )Nz+++ exception)r/   re   )r   r1   Z	exc_stuffr   r   r   rF   Q  s    
zTdb.user_exceptionN)r   r	   r
   r>   r6   rB   rF   r   r   r   r   r   C  s   r   c                 C   s&   t d| d t| d }t d| d S )Nzfoo()
   zbar returned)r/   bar)nxr   r   r   fooU  s    r   c                 C   s   t d| d | d S )Nzbar(r   rD   r   )ar   r   r   r   Z  s    r   c                  C   s   t  } | d d S )Nzimport bdb; bdb.foo(10))r   r   )r   r   r   r   test^  s    r   )rI   ra   r   inspectr   r   r   __all__r=   	Exceptionr   r   rd   r   r   rQ   r   r   r   r   r   r   r   r   <module>   s&       kt"0