
    Vpf                        d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z ej        Z G d dej                  ZddZ ej        ded           dS )    )annotationsN)AnyIO)corec                       e Zd ZdZdZ	 	 dd fdZd Zd Zd Zd Z	ddZ
d Zd Zd Zd ZeZd ZeZd ZeZd ZexZZd ZexZxZZd ZexZZd Z xZS ) CliDebuggerzA text-based debugger.z(jdb) Ntabframeslist[DebuggerFrame]stdinIO[str] | Nonestdoutcompletekeystrc                    t                                          |||           |d u | _        || _        d| _        || _        d| _        d S )N)r   r   r   r   zEntering jdb:)super__init__use_rawinputr
   frame_index	thread_idintro)selfr
   r   r   r   r   	__class__s         ^/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/debugger/cli_debugger.pyr   zCliDebugger.__init__   sQ     
GG5[IIIDDKDDN DJJJ    c                &    | j         | j                 S N)r
   r   r   s    r   current_framezCliDebugger.current_frame(   s    ;t'((r   c                    i }| j         | j                 }|                    |j                   |                    |j                   t          |i |          S r   )r
   r   updateglobalslocalseval)r   exprenv
curr_frames       r   evaluatezCliDebugger.evaluate+   sR    
CT-.JJJz!"""JJz !!!b#r   c                    	 t          t          |                     |                    | j                   dS #  |                                  Y dS xY w)zEvaluates an expression.fileNprintreprr(   r   _error_messager   args     r   defaultzCliDebugger.default2   sZ    Ds##$$4;777777
	   6: Ac                   g }|                     d           | j        d d d         D ]}|                     d|j         d|j                    |j        |                     d           D|j        |j                 }|                     d|                                            t          d                    |          | j	                   d S )	Nz
Traceback:z  File "z", line z    <no source>    
r*   )
appendr
   filenamelinenooffsetsourcestripr-   joinr   )r   	backtraceframelines       r   print_backtracezCliDebugger.print_backtrace9   s    I\"""TTrT" 0 0H%.HH%,HHIII		*++++|EL).

..////	$))I

T[111111r      c                   | j         | j                 }g }|                    d|j         d|j         d           t          |j                  D ]m\  }}|j        J |j        dz
  |z
  |cxk    r|j        |z   k    r?n 1||j        k    r|                    d|            U|                    d|            nt          d	                    |          | j
                   d S )	Nz> ()   z->  r6   r7   r*   )r
   r   r8   r9   r:   	enumerater<   r;   r-   r>   r   )r   	num_linesr'   contextirA   s         r   print_contextzCliDebugger.print_contextE   s"   T-.JGNNB
+BBj.?BBBCCCZ.// ( (4***

a
)
+q ( ( ( (

i
'( ( ( ( (
!!!
..
'
'
'
'
..
'
'
'	$))G

4;//////r   c                    t          j                    d d         }t          j        | d                                         }t          d|| j                   d S )NrC   r5   z***r*   )sysexc_info	tracebackformat_exception_onlyr=   r-   r   )r   rO   msgs      r   r/   zCliDebugger._error_messageS   sQ    |~~bqb!H

)8
4R
8
>
>
@
@C	%4;''''''r   c                    	 t          t          |                     |                    | j                   dS #  |                                  Y dS xY w)zEp expression
    Evaluates and prints the value of an expression
    r*   Nr,   r0   s     r   do_pzCliDebugger.do_pX   sZ    Ds##$$4;777777
r3   c                    	 t          t          j        |                     |                    | j                   dS #  |                                  Y dS xY w)zMpp expression
    Evaluates and pretty-prints the value of an expression
    r*   N)r-   pprintpformatr(   r   r/   r0   s     r   do_ppzCliDebugger.do_ppa   s\    FN4==--..T[AAAAAA
s	   ;? Ac                    | j         t          | j                  dz
  k    rt          d| j                   n| xj         dz  c_         |                                  dS )z&u(p)
    Move down a stack frame.
    rG   zAt topmost frame.r*   N)r   lenr
   r-   r   rL   r   _s     r   do_upzCliDebugger.do_upj   sf     3t{++a///dk22222
!r   c                    | j         dk    rt          d| j                   n| xj         dz  c_         |                                  dS )z(d(own)
    Move down a stack frame.
    r   zAt bottommost frame.r*   rG   N)r   r-   r   rL   r[   s     r   do_downzCliDebugger.do_downu   sW     1"55555
!r   c                2    |                      d           dS )z6l(ist)
    List source code for the current file.
       )rI   N)rL   r[   s     r   do_listzCliDebugger.do_list   s!     	#####r   c                    dS )z7c(ont(inue))
    Continue the program's execution.
    T r[   s     r   do_continuezCliDebugger.do_continue   s	     4r   c                .    t          j        d           dS )zOq(uit)
(exit)
    Quit the debugger. The program is given an exit command.
    r   N)rN   exitr[   s     r   do_quitzCliDebugger.do_quit   s     HQKKKKKr   c                .    |                                   dS )zvw(here)
    Prints a stack trace with the most recent frame on the bottom.
    'bt' is an alias for this command.
    N)rB   r[   s     r   do_wherezCliDebugger.do_where   s    
 	r   c                    	 	 |                                   d S # t          $ r t          dt          j                   Y nw xY wC)NTz--KeyboardInterrupt--r*   )cmdloopKeyboardInterruptr-   rN   r   r   s    r   runzCliDebugger.run   sZ    88 8 8 8%CJ7777778	8s    %A A)NNr	   )r
   r   r   r   r   r   r   r   )rC   ) __name__
__module____qualname____doc__promptr   r   r(   r2   rB   rL   r/   rT   rX   r]   do_ur_   do_drb   do_lre   do_cdo_contrh   do_qdo_EOFdo_exitrj   do_wdo_btrn   __classcell__)r   s   @r   r   r      sz       & >B! ! ! ! ! ! !) ) )    
2 
2 
20 0 0 0( ( (
       
$   
$$ $ $
 
$  
 $  
 $#$#'   $8 8 8 8 8 8 8r   r   r
   r   r   
int | Nonekwargsr   c                F    t          | |fi |                                 d S r   )r   rn   )r
   r   r   s      r   run_debuggerr      s,    fi**6**..00000r   clir5   )r
   r   r   r   r   r   )
__future__r   cmdrV   rN   rP   typingr   r   jax._src.debuggerr   debugger_coreDebuggerFrameCmdr   r   register_debuggerrd   r   r   <module>r      s    # " " " " " 



  



             3 3 3 3 3 3+I8 I8 I8 I8 I8#' I8 I8 I8V1 1 1 1   |R 8 8 8 8 8r   