
    hQgQ                        d Z ddlZddlZddlT ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ  G d d	ej                  Zd
 Zd Z G d d          Z G d de
          Z G d d          Zedk    rddlmZ  eddd           dS dS )a  Debug user code with a GUI interface to a subclass of bdb.Bdb.

The Idb idb and Debugger gui instances each need a reference to each
other or to an rpc proxy for each other.

If IDLE is started with '-n', so that user code and idb both run in the
IDLE process, Debugger is called without an idb.  Debugger.__init__
calls Idb with its incomplete self.  Idb.__init__ stores gui and gui
then stores idb.

If IDLE is started normally, so that user code executes in a separate
process, debugger_r.start_remote_debugger is called, executing in the
IDLE process.  It calls 'start the debugger' in the remote process,
which calls Idb with a gui proxy.  Then Debugger is called in the IDLE
for more.
    N)*)Frame	Scrollbar)macosx)ScrolledList)ListedToplevelc                   .     e Zd ZdZ fdZd Zd Z xZS )Idbz6Supply user_line and user_exception functions for Bdb.c                 V    || _         t                                                       d S N)guisuper__init__)selfr   	__class__s     "  /home/conda/feedstock_root/build_artifacts/python-split_1733407214354/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/python3.11/idlelib/debugger.pyr   zIdb.__init__    s&        c                     t          |          r|                                  dS t          |          }	 | j                            ||           dS # t
          $ r Y dS w xY w)zmHandle a user stopping or breaking at a line.

        Convert frame to a string and send it to gui.
        N)_in_rpc_codeset_step_frame2messager   interactionTclError)r   framemessages      r   	user_linezIdb.user_line$   sx    
  	MMOOOF ''	H  %00000 	 	 	DD	s   A 
A! A!c                     t          |          r|                                  dS t          |          }| j                            |||           dS )z)Handle an the occurrence of an exception.N)r   r   r   r   r   )r   r   exc_infor   s       r   user_exceptionzIdb.user_exception2   sQ     	MMOOOF ''WeX66666r   )__name__
__module____qualname____doc__r   r   r   __classcell__)r   s   @r   r
   r
      s\        <<      7 7 7 7 7 7 7r   r
   c                     | j         j                            d          rdS | j        }|dS |j         j        }d|v rd|v rdS t	          |          S )z)Determine if debugger is within RPC code.zrpc.pyTNFidlelibdebugger)f_codeco_filenamecountf_backr   )r   
prev_frame	prev_names      r   r   r   :   si    |%%h// (t\
5%1		!!jI&=&= 5J'''r   c                     | j         }|j        }| j        }t          j                            |          }| d| }|j        dk    r| d|j         d}|S )z"Return a message string for frame.:?: z())r(   r)   f_linenoospathbasenameco_name)r   codefilenamelinenor5   r   s         r   r   r   I   sj    <DH^Fw))H$$F$$G|s00000Nr   c                       e Zd ZdZdZdZdZdZdZdZ	dZ
ddZd ZddZd ZddZd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Z d Z!dS )DebuggerzThe debugger interface.

    This class handles the drawing of the debugger window and
    the interactions with the underlying debugger session.
    Nc                     |t          |           }|| _        || _        d| _        |                                  d| _        d| _        dS )a  Instantiate and draw a debugger window.

        :param pyshell: An instance of the PyShell Window
        :type  pyshell: :class:`idlelib.pyshell.PyShell`

        :param idb: An instance of the IDLE debugger (optional)
        :type  idb: :class:`idlelib.debugger.Idb`
        NFr   )r
   pyshellidbr   make_guiinteractingnesting_level)r   r=   r>   s      r   r   zDebugger.__init__c   sL     ;d))C
 r   c                       j         dk    r5                                   j                            d fd           dS 	 d _          j        j         d _        S # d _        w xY w)zRun the debugger.r   d   c                       j           S r   )run)argsr   s   r   <lambda>zDebugger.run.<locals>.<lambda>   s    4 r   NTF)rA   
abort_looprootafterr@   r>   rE   )r   rF   s   ``r   rE   zDebugger.runu   s    > !!OOIOOC!8!8!8!8!8999F	%#D48<&$DuD$$$$s   A! !	A*c                 H   	 |                                   n# t          $ r Y nw xY w| j        r| j                                         dS | j        r | j                                         d| _        | j                                         | j        	                                 dS )zClose the debugger and window.N)
quit	Exceptionr@   topbellstackviewercloser=   close_debuggerdestroyr   events     r   rQ   zDebugger.close   s    	IIKKKK 	 	 	D	 	HMMOOOF 	>""$$$d&6 	##%%%s    
$$c                    | j         }|j        | _        |j        x| _        }t          |          x| _        }| j                            d           | j                            d           |                    d| j                   | j        	                    d| j                   t          |          x| _        }| j                            d           g x| _        }t          |d| j                  x| _        }|                    |           t          |d	| j                  x| _        }|                    |           t          |d
| j                  x| _        }|                    |           t          |d| j                  x| _        }|                    |           t          |d| j                  x| _        }|                    |           |D ].}|                    d           |                    d           /t          |          x| _        }| j                            d           | j        s3t9          |          | j        _        | j                            d           t?          |d| j         | j                  | _!        | j!        "                    dd           | j#        st9          |          | j        _#        t?          |d| j$        | j#                  | _%        | j%        "                    dd           | j&        s3t9          |          | j        _&        | j&                            d           t?          |d| j'        | j&                  | _(        | j(        "                    dd           | j)        st9          |          | j        _)        t?          |d| j*        | j)                  | _+        | j+        "                    dd           tY          |d          | _-        | j-                            d           tY          |d          | _.        | j.                            dd           | j.        /                    d          | _0        t          |d          | _1        | j1                            dd           t          |          | _2        | j2                            dd           t          |d          | _3        | j3                            dd           | j        4                                r|                                   | j&        4                                r| '                                 | j)        4                                r| *                                 dS dS ) z$Draw the debugger gui on the screen.zDebug ControlDebugWM_DELETE_WINDOWz<Escape>w)anchorGo)textcommandStepOverOutQuitdisabledstateleft)side   Stack)r\   r]   variabler   rowcolumnSourceLocalsGlobalsx)rZ   fill
background)heightbothexpandrq   N)5r=   flistrI   r   rN   wm_titlewm_iconnamewm_protocolrQ   bindr   bframepackbuttonsButtoncontbcontappendstepbstepnextbnextretbretrL   	configurecframevstack
BooleanVarr   setCheckbutton
show_stackbstackgridvsourceshow_sourcebsourcevlocalsshow_localsblocalsvglobalsshow_globalsbglobalsLabelstatuserrorcgeterrorbgfstackflocalsfglobalsget)r   r=   rI   rN   r|   blbr   s           r   r?   zDebugger.make_gui   s   ,]
"<'	D'---3/***W%%%*DJ777j$*---$Szz)f$$$rT49EEEE
Q
		!VTYGGGG
Q
		!VTYGGGG
Q
		!vE48DDDD	A
		!vFDIFFFF	A
		! 	  	 AKKjK)))FFF$V}},ff%%%{ 	$.sOODN!KOOA!&$/DKI I IQq)))| 	5%/__DN""64#3dlL L La***| 	 %/__DN"LQ"64#3dlL L La***} 	6&0ooDN##FD$5O O Oq+++C,,,$$$3s+++

s---z|44C***///Szz000c!,,,!&111;?? 	OO< 	= 	 	  	 r   c                    || _         | j                            |           |rF|\  }}}	 |j        }n"# t          $ r dt          |          z  }Y nw xY w|	 | d| }n#  Y nxY wd}nd}d }| j        }| j                            ||           | j        }	|	r9| j	        
                    | j         |          \  }
}|	                    |
|           |                     d           | j                                        r|                                  | j        D ]}|                    d	           | j                                         | xj        dz  c_        | j        j                            d
d           | xj        dz  c_        | j        D ]}|                    d	           | j                            d           | j                            d| j                   d | _         d S )Nr\   z%sr1   yellow )r\   rr   rg   normalrc   vwait::idledebugwaitrb   )r   r   r   r    AttributeErrorstrr   r   rP   r>   	get_stack
load_stackshow_variablesr   r   sync_source_liner~   rN   wakeuprA   rI   tkcall)r   r   r   infotypevaluetbm1bgsvstackir   s                r   r   zDebugger.interaction   s8   
7+++ 	"OD%&]! & & &CII%& ))%))BBDBBBBB
"444 	$x))$*b99HE1MM%###A< 	$!!### 	( 	(AKKhK'''' 	a	'#4555a 	* 	*AKKjK))))2&&&
">>>


s   4 AAA! !A%c                     | j         }|sd S |                     |          \  }}|d d         |dd          z   dk    r<t          j                            |          r| j                            ||           d S d S d S )Nrg   z<>)r   _Debugger__frame2fileliner3   r4   existsrw   gotofileline)r   r   r8   r9   s       r   r   zDebugger.sync_source_line.  s    
 	F0077&BQB<(233-'4//BGNN84L4L/J##Hf55555 0///r   c                 4    |j         }|j        }|j        }||fS r   )r(   r)   r2   )r   r   r7   r8   r9   s        r   __frame2filelinezDebugger.__frame2fileline6  s#    |#r   c                 `    | j                                          |                                  d S r   )r>   set_continuerH   r   s    r   r   zDebugger.cont<  s,    r   c                 `    | j                                          |                                  d S r   )r>   r   rH   r   s    r   r   zDebugger.step@  ,    r   c                 l    | j                             | j                   |                                  d S r   )r>   set_nextr   rH   r   s    r   r   zDebugger.nextD  s0    $*%%%r   c                 l    | j                             | j                   |                                  d S r   )r>   
set_returnr   rH   r   s    r   r   zDebugger.retH  s0    DJ'''r   c                 `    | j                                          |                                  d S r   )r>   set_quitrH   r   s    r   rL   zDebugger.quitL  r   r   c                 H    | j         j                            ddd           d S )Nr   r   1)rI   r   r   r   s    r   rH   zDebugger.abort_loopP  s%    	%!2C88888r   c                    | j         s| j                                        rft          | j        | j        |           x| _         }| j        r;| j                            | j        d           \  }}|	                    ||           d S d S | j         }|r4| j                                        sd | _         |
                                 d| j        d<   d S )Nrg   rs   )rP   r   r   StackViewerr   rw   r   r>   r   r   rQ   )r   r   r   r   s       r   r   zDebugger.show_stackS  s     
	&DKOO$5$5 
	&$/TZ$N$NNDrz (8--dj$??qeQ'''''( ( !B $+//++ #' 


$%DK!!!r   c                 d    | j                                         r|                                  d S d S r   )r   r   r   r   s    r   r   zDebugger.show_source`  s:    < 	$!!#####	$ 	$r   c                 H    |d         | _         |                                  d S Nr   )r   r   )r   	stackitems     r   
show_framezDebugger.show_framed  s%    q\
r   c                     | j         }| j                                        r|st          | j        d          | _         n'|r%d | _         |                                 d| j        d<   |                                  d S )Nrn   rg   rs   )localsviewerr   r   NamespaceViewerr   rQ   r   )r   lvs     r   r   zDebugger.show_localsh  s    < 	+ L$3DL($K$K! +$(!


)*X&r   c                     | j         }| j                                        r|st          | j        d          | _         n'|r%d | _         |                                 d| j        d<   |                                  d S )Nro   rg   rs   )globalsviewerr   r   r   r   rQ   r   )r   gvs     r   r   zDebugger.show_globalst  s    = 	, O%4T]I%N%N" ,%)"


*+h'r   r   c                    | j         }| j        }| j        }|sd x}}n|j        }|j        }|r|r||u rd }|r&|                    ||| j        j        j                   |r(|                    ||| j        j        j                   d S d S r   )	r   r   r   f_locals	f_globals	load_dictr=   interprpcclt)r   forcer   r   r   ldictgdicts          r   r   zDebugger.show_variables  s    
 	  EEENEOE b Ue^^ 	CLLt|':'ABBB 	CLLt|':'ABBBBB	C 	Cr   c                 <    | j                             ||           dS )zzSet a filename-lineno breakpoint in the debugger.

        Called from self.load_breakpoints and EW.setbreakpoint
        N)r>   	set_breakr   r8   r9   s      r   set_breakpointzDebugger.set_breakpoint  s"    
 	8V,,,,,r   c                 <    | j                             ||           d S r   )r>   clear_breakr   s      r   clear_breakpointzDebugger.clear_breakpoint  s     Xv.....r   c                 :    | j                             |           d S r   )r>   clear_all_file_breaks)r   r8   s     r   clear_file_breakszDebugger.clear_file_breaks  s    &&x00000r   c                     | j         j        j        D ]?}|j        j        }	 |j        D ]}|                     ||           0# t          $ r Y <w xY wdS )z>Load PyShellEditorWindow breakpoints into subprocess debugger.N)r=   rw   inversedictior8   breakpointsr   r   )r   editwinr8   r9   s       r   load_breakpointszDebugger.load_breakpoints  s    |)5 	 	Gz*H%1 : :F''&9999:!   	 	s    A
AAr   )r   )"r    r!   r"   r#   r   r   r   r   rP   r   r   r   rE   rQ   r?   r   r   r   r   r   r   r   rL   rH   r   r   r   r   r   r   r   r   r   r    r   r   r;   r;   U   s        
 FGGHKLM   $'% '% '%R   $J  J  J X0 0 0 0d6 6 6               9 9 9& & &$ $ $  
 
 

 
 
C C C C - - -/ / /1 1 1    r   r;   c                   J    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd ZdS )r   z#Code stack viewer for debugger GUI.c                     t          j                    rt          j        | |           nt          j        | |d           || _        || _        g | _        d S )NP   )width)r   isAquaTkr   r   rw   r   r   )r   masterrw   r   s       r   r   zStackViewer.__init__  s[    ? 	: !$////!$b9999



r   Nc                    || _         |                                  t          t          |                    D ]}||         \  }}	 |j        d         }n	#  d}Y nxY w|j        }|j        }|j        }	dd l}
|
	                    ||          }|
                                }|	dv r	d|||fz  }n	d||	||fz  }||k    rd|z   }|                     |           ||                     |           d S d S )Nr    r0   r   )r0   r   Nz%s, line %d: %sz%s.%s(), line %d: %sz> )r   clearrangelenr   r(   r)   r6   	linecachegetlinestripr   select)r   r   indexr   r   r9   modnamer7   r8   funcnamer  
sourcelineitems                r   r   zStackViewer.load_stack  s2   


s5zz"" 	 	A!!HME6/*5<D'H|H"**8V<<J#))++J?**(GVZ+HH-(171E EEzzd{KKKK s   AAc                 >    | j         rt          j        | |          S dS Override base method.N)r   r   popup_eventrT   s     r   r  zStackViewer.popup_event  s)    : 	9+D%888	9 	9r   c                     | j         }|                    d| j                   |                    d| j                   dS )r  zGo to source line)labelr]   zShow stack frameN)menuadd_commandgoto_source_lineshow_stack_frame)r   r  s     r   	fill_menuzStackViewer.fill_menu  s_    y2!%!6 	 	8 	8 	81!%!6 	 	8 	8 	8 	8 	8r   c                     d|cxk    rt          | j                  k     r+n dS | j                            | j        |                    dS dS )r  r   N)r  r   r   r   r   r	  s     r   	on_selectzStackViewer.on_select  sZ    ''''DJ''''''H
5 122222 ('r   c                 0    |                      |           dS r  )r   r  s     r   	on_doublezStackViewer.on_double  s    r   c                 d    | j                             d          }|                     |           d S )Nactive)listboxr	  r   r  s     r   r  zStackViewer.goto_source_line  s1    ""8,,r   c                     | j                             d          }d|cxk    rt          | j                  k     r+n d S | j                            | j        |                    d S d S )Nr  r   )r   r	  r  r   r   r   r  s     r   r  zStackViewer.show_stack_frame  so    ""8,,''''DJ''''''H
5 122222 ('r   c                 0   d|cxk    rt          | j                  k     sn d S | j        |         \  }}|j        }|j        }t          j                            |          r3| j                            |          }|r|	                    |           d S d S d S r   )
r  r   r(   r)   r3   r4   isfilerw   opengotoline)r   r	  r   r9   r7   r8   edits          r   r   zStackViewer.show_source  s    U,,,,S__,,,,F
5)v|#7>>(## 	&:??8,,D &f%%%%%	& 	&& &r   r   )r    r!   r"   r#   r   r   r  r  r  r  r  r  r   r   r   r   r   r     s        ))
 
 
   49 9 9
8 8 83 3 3
          3 3 3
	& 	& 	& 	& 	&r   r   c                   ,    e Zd ZdZddZdZd	dZd ZdS )
r   z/Global/local namespace viewer for debugger GUI.Nc           
      @   d}d}|rdt          |          z  }|| _        || _        dd l}|                                | _        d| j        _        d| j        _        t          |          x| _	        }| j	        
                    dd           t          ||dd	
          | _        | j        
                    d           t          |d          x| _        }|
                    dd           t          |t!          dt#          d|                    dd||f          x| _        }	|	
                    ddd           |	j        |d<   |j        |	d<   t          |	          x| _        }
|	                    dd|
d          | _        |                     |           d S )Nr   (      <   rg   rt   ru      groove)r\   borderwidthreliefrp   )rq   vbar)namerighty)rf   rq   ,  )rs   scrollregionre   )rf   rq   rv   r]   yscrollcommandnw)windowrZ   )r  r   titlereprlibReprrepr	maxstringmaxotherr   r   r}   r   r  r   r0  Canvasminmaxcanvasyviewr   subframecreate_windowsfidr   )r   r   r9  odictr   rs   r:  r   r0  rB  rD  s              r   r   zNamespaceViewer.__init__  s    	#E

]F
LLNN	 		"6]]*
U
qv...5u!HMMM

S!!!$U8888	D		wS	)))%e-0c"foo-F-F45q%3H J  J  J 	Jf 	fQ777 ,Y#'8 #(==0((Aht(LL	ur   r   r   c                    || j         u r|sd S | j        }| j        }t          |j                                                  D ]}|                                 d | _         |s)t          |d          }|                    dd           n|	                                }t          |          }	d}
|	D ]}||         }| j                            |          }|r
|dd         }t          ||          }|                    |
dd           t          |dd	          }|                    d|           |                    |
dd           |
dz   }
|| _         |                                 |                                }|                                }| j        }dd||f| j        d
<   |dk    rd|d<   |                    d           d S ||d<   |                    d           d S )NNoner   r   rj   rg   r   r7  )rk   rl   sticky)r   r.  r5  r4  rs   )rv   )
prev_odictrD  r   listchildrenvaluesrS   r   r   keyssortedr<  Entryinsertupdate_idletaskswinfo_reqwidthwinfo_reqheightrB  r}   )r   rG  r   
rpc_clientrD  r   cl	keys_listnamesrk   r1  r   svaluer   rs   rB  s                    r   r   zNamespaceViewer.load_dict  s   DO##E#F=
h'..0011 	 	AIIKKKK 	hV,,,AFFqF#### 

I9%%EC  d..  *#AbD\F(...3q666(!;;;F###3q666!e!!###''))))++'(!UF&;N#C<<"F8JJaJ     %F8JJaJ     r   c                 8    | j                                          d S r   )r   rS   r   s    r   rQ   zNamespaceViewer.closeR  s    
r   r   )r   N)r    r!   r"   r#   r   rK  r   rQ   r   r   r   r   r     sY        55   6 J4! 4! 4! 4!l    r   r   __main__)mainzidlelib.idle_test.test_debuggerr,  F)	verbosityexit)r#   bdbr3   tkintertkinter.ttkr   r   r&   r   idlelib.scrolledlistr   idlelib.windowr   Bdbr
   r   r   r;   r   r   r    unittestr^  r   r   r   <module>rh     s   " 


 				     ( ( ( ( ( ( ( (       - - - - - - ) ) ) ) ) )7 7 7 7 7#' 7 7 7:( ( (	 	 	P P P P P P P Pf
Q& Q& Q& Q& Q&, Q& Q& Q&hW W W W W W W Wt zD	*aeDDDDDD r   