m
fIc           @   s   d  Z  d k Z d k Z d k Z d d d g Z d e f d     YZ d f  d     YZ d   Z d f  d     YZ	 d	   Z
 d
   Z d e f d     YZ d   Z d   Z d   Z d S(   s   Debugger basicsNt   BdbQuitt   Bdbt
   Breakpointc           B   s   t  Z d  Z RS(   s   Exception to give up completely(   t   __name__t
   __module__t   __doc__(    (    (    t    /mit/python/lib/python2.4/bdb.pyR    	   s   c           B   sv  t  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   Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d e e d  Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d    Z" d!   Z# d" d#  Z$ e e d$  Z% e e d%  Z& d&   Z' d'   Z( RS((   s   Generic Python debugger base class.

    This class takes care of details of the trace facility;
    a derived class should implement user interaction.
    The standard debugger class (pdb.Pdb) is an example.
    c         C   s   h  |  _ h  |  _ d  S(   N(   t   selft   breakst   fncache(   R   (    (    R   t   __init__   s    	c         C   sv   | d | d d !d j o | Sn |  i i |  } | p5 t i i |  } t i i |  } | |  i | <n | S(   Nt   <i   it   >(	   t   filenameR   R	   t   gett   canonict   ost   patht   abspatht   normcase(   R   R   R   (    (    R   R      s    c         C   s;   d  k  } | i   d  |  _ d  |  _ d  |  _ d |  _ d  S(   Ni    (   t	   linecachet
   checkcachet   NoneR   t   botframet	   stopframet   returnframet   quitting(   R   R   (    (    R   t   reset$   s    	
			c         C   s   |  i o d  Sn | d j o |  i |  Sn | d j o |  i | |  Sn | d j o |  i | |  Sn | d j o |  i | |  Sn | d j o |  i	 Sn | d j o |  i	 Sn | d j o |  i	 Sn d Gt
 |  GH|  i	 S(	   Nt   linet   callt   returnt	   exceptiont   c_callt   c_exceptiont   c_returns*   bdb.Bdb.dispatch: unknown debugging event:(   R   R   t   eventt   dispatch_linet   framet   dispatch_callt   argt   dispatch_returnt   dispatch_exceptiont   trace_dispatcht   repr(   R   R%   R#   R'   (    (    R   R*   ,   s$    
c         C   sL   |  i |  p |  i |  o% |  i |  |  i o
 t  qE n |  i S(   N(   R   t	   stop_hereR%   t
   break_heret	   user_lineR   R    R*   (   R   R%   (    (    R   R$   @   s
     
 c         C   sz   |  i d  j o | i |  _ |  i Sn |  i |  p |  i |  p d  Sn |  i | |  |  i
 o
 t  n |  i S(   N(   R   R   R   R%   t   f_backR*   R,   t   break_anywheret	   user_callR'   R   R    (   R   R%   R'   (    (    R   R&   F   s     
 
c         C   sO   |  i |  p | |  i j o( |  i | |  |  i o
 t  qH n |  i S(   N(	   R   R,   R%   R   t   user_returnR'   R   R    R*   (   R   R%   R'   (    (    R   R(   S   s
     
 c         C   s?   |  i |  o( |  i | |  |  i o
 t  q8 n |  i S(   N(   R   R,   R%   t   user_exceptionR'   R   R    R*   (   R   R%   R'   (    (    R   R)   Y   s
    
 c         C   sb   | |  i j o t Sn xC | d  j	 o5 | |  i j	 o% | |  i j o t Sn | i } q Wt S(   N(   R%   R   R   t   TrueR   R   R/   t   False(   R   R%   (    (    R   R,   c   s     c         C   s   |  i | i i  } | |  i j o t Sn | i } | |  i | j o, | i i
 } | |  i | j o t Sqv n t | | |  \ } } | o? | i |  _ | o$ | i o |  i t | i   n t Sn t Sd  S(   N(   R   R   R%   t   f_codet   co_filenameR   R   R5   t   f_linenot   linenot   co_firstlinenot	   effectivet   bpt   flagt   numbert	   currentbpt	   temporaryt   do_cleart   strR4   (   R   R%   R   R=   R<   R9   (    (    R   R-   n   s    	c         C   s   t  d  d  S(   Ns)   subclass of bdb must implement do_clear()(   t   NotImplementedError(   R   R'   (    (    R   RA      s    c         C   s   |  i i |  i | i i   S(   N(   R   R   t   has_keyR   R%   R6   R7   (   R   R%   (    (    R   R0      s    c         C   s   d S(   sn   This method is called when there is the remote possibility
        that we ever need to stop in this function.N(    (   R   R%   t   argument_list(    (    R   R1      s    c         C   s   d S(   s9   This method is called when we stop or break at this line.N(    (   R   R%   (    (    R   R.      s    c         C   s   d S(   s5   This method is called when a return trap is set here.N(    (   R   R%   t   return_value(    (    R   R2      s    c         C   s   | \ } } } d S(   sm   This method is called if an exception occurs,
        but only if we are to stop at or just below this level.N(   t   exc_typet	   exc_valuet   exc_traceback(   R   R%   t   .4RG   RH   RI   (    (    R   R3      s   c         C   s   d |  _ d |  _ d |  _ d S(   s   Stop after one line of code.i    N(   R   R   R   R   R   (   R   (    (    R   t   set_step   s     		c         C   s   | |  _ d |  _ d |  _ d S(   s2   Stop on the next line in or below the given frame.i    N(   R%   R   R   R   R   R   (   R   R%   (    (    R   t   set_next   s     		c         C   s"   | i |  _ | |  _ d |  _ d S(   s)   Stop when returning from the given frame.i    N(   R%   R/   R   R   R   R   (   R   R%   (    (    R   t
   set_return   s     	c         C   su   | d j o t i   i } n |  i   x* | o" |  i | _ | |  _	 | i } q- W|  i
   t i |  i  d S(   sp   Start debugging from `frame`.

        If frame is not specified, debugging starts from caller's frame.
        N(   R%   R   t   syst	   _getframeR/   R   R   R*   t   f_traceR   RK   t   settrace(   R   R%   (    (    R   t	   set_trace   s     
 	
c         C   sz   |  i |  _ d  |  _ d |  _ |  i pN t i d   t i	   i
 } x/ | o# | |  i j	 o | ` | i
 } qG Wn d  S(   Ni    (   R   R   R   R   R   R   R   RN   RQ   RO   R/   R%   RP   (   R   R%   (    (    R   t   set_continue   s    		
 c         C   s/   |  i |  _ d  |  _ d |  _ t i d   d  S(   Ni   (   R   R   R   R   R   R   RN   RQ   (   R   (    (    R   t   set_quit   s    		i    c   
      C   s   |  i |  } d  k } | i | |  }	 |	 p d | | f Sn | |  i j o g  |  i | <n |  i | } | | j o | i	 |  n t
 | | | | |  } d  S(   Ns   Line %s:%d does not exist(   R   R   R   R   t   getlineR9   R   R   t   listt   appendR   R@   t   condt   funcnameR<   (
   R   R   R9   R@   RX   RY   RV   R   R<   R   (    (    R   t	   set_break   s    	c         C   s   |  i |  } | |  i j o d | Sn | |  i | j o d | | f Sn x& t i | | f D] } | i   qf Wt i i	 | | f  p |  i | i
 |  n |  i | p |  i | =n d  S(   Ns   There are no breakpoints in %ss   There is no breakpoint at %s:%d(   R   R   R   R   R9   R   t   bplistR<   t   deleteMeRD   t   remove(   R   R   R9   R<   (    (    R   t   clear_break   s     c         C   s~   y t  |  } Wn d | Sn Xy t i | } Wn t j
 o d | Sn X| p d | Sn |  i | i	 | i
  d  S(   Ns"   Non-numeric breakpoint number (%s)s#   Breakpoint number (%d) out of ranges   Breakpoint (%d) already deleted(   t   intR'   R>   R   t
   bpbynumberR<   t
   IndexErrorR   R^   t   fileR   (   R   R'   R>   R<   (    (    R   t   clear_bpbynumber   s    c         C   s   |  i |  } | |  i j o d | Sn xC |  i | D]4 } t i | | f } x | D] } | i	   qY Wq9 W|  i | =d  S(   Ns   There are no breakpoints in %s(
   R   R   R   R   R   R   R[   t   blistR<   R\   (   R   R   Rd   R<   R   (    (    R   t   clear_all_file_breaks
  s      c         C   sH   |  i p d Sn x& t i D] } | o | i   q q Wh  |  _ d  S(   Ns   There are no breakpoints(   R   R   R   R`   R<   R\   (   R   R<   (    (    R   t   clear_all_breaks  s    

 c         C   s0   |  i |  } | |  i j o | |  i | j S(   N(   R   R   R   R   R9   (   R   R   R9   (    (    R   t	   get_break  s    c         C   sK   |  i |  } | |  i j o( | |  i | j o t i | | f p g  S(   N(   R   R   R   R   R9   R   R[   (   R   R   R9   (    (    R   t
   get_breaks!  s    c         C   s6   |  i |  } | |  i j o |  i | Sn g  Sd  S(   N(   R   R   R   R   (   R   R   (    (    R   t   get_file_breaks'  s    c         C   s   |  i S(   N(   R   R   (   R   (    (    R   t   get_all_breaks.  s    c         C   s   g  } | o | i | j o | i } n xF | d  j	 o8 | i | | i f  | |  i	 j o Pn | i
 } q- W| i   t d t |  d  } x4 | d  j	 o& | i | i | i f  | i } q W| | f S(   Ni    i   (   t   stackt   tt   tb_framet   ft   tb_nextR   RW   R8   R   R   R/   t   reverset   maxt   lent   it	   tb_lineno(   R   Rn   Rl   Rs   Rk   (    (    R   t	   get_stack4  s      
 s   : c         C   s0  d  k  } d  k } | \ }
 } |  i |
 i i  } d | | f } |
 i i o | |
 i i } n | d } d |
 i j o |
 i d } n d  } | o | | i |  } n | d } d |
 i j o. |
 i d } | d } | | i |  } n | i | |  }	 |	 o | | |	 i   } n | S(   Ns   %s(%r)s   <lambda>t   __args__s   ()t
   __return__s   ->(   R   R+   t   frame_linenoR%   R9   R   R   R6   R7   R   t   st   co_namet   f_localst   argsR   t   rvRU   R   t   lprefixt   strip(   R   Rx   R~   R|   R+   R   R   Ry   R}   R   R%   R9   (    (    R   t   format_stack_entryF  s*    


 c         B   s   | d  j o d  k } | i } n | d  j o
 | } n |  i   e i |  i	  e
 | e i  p | d } n z( y | | | UWn e j
 o n XWd  d |  _ e i d   Xd  S(   Ns   
i   (   t   globalsR   t   __main__t   __dict__t   localsR   R   RN   RQ   R*   t
   isinstancet   cmdt   typest   CodeTypeR    R   (   R   R   R   R   R   (    (    R   t   runb  s"    	

	 	c         C   s   | d  j o d  k } | i } n | d  j o
 | } n |  i   t i |  i	  t
 | t i  p | d } n z. y t | | |  SWn t j
 o n XWd  d |  _ t i d   Xd  S(   Ns   
i   (   R   R   R   R   R   R   R   RN   RQ   R*   R   t   exprR   R   t   evalR    R   (   R   R   R   R   R   (    (    R   t   runevalu  s"    	

	 	c         C   s   |  i | | |  d  S(   N(   R   R   R   R   R   (   R   R   R   R   (    (    R   t   runctx  s    c         O   sk   |  i   t i |  i  d  } z- y | | |   } Wn t
 j
 o n XWd  d |  _ t i d   X| S(   Ni   (   R   R   RN   RQ   R*   R   t   rest   funcR|   t   kwdsR    R   (   R   R   R|   R   R   (    (    R   t   runcall  s    
	 	()   R   R   R   R
   R   R   R*   R$   R&   R(   R)   R,   R-   RA   R0   R1   R.   R2   R3   RK   RL   RM   R   RR   RS   RT   RZ   R^   Rc   Re   Rf   Rg   Rh   Ri   Rj   Ru   R   R   R   R   R   (    (    (    R   R      sL    		
						
																
							c           C   s   t    i   d  S(   N(   R   RR   (    (    (    R   RR     s    c           B   sY   t  Z d  Z d Z h  Z e g Z d e e d  Z d   Z d   Z	 d   Z
 d   Z RS(   s  Breakpoint class

    Implements temporary breakpoints, ignore counts, disabling and
    (re)-enabling, and conditionals.

    Breakpoints are indexed by number through bpbynumber and by
    the file,line tuple using bplist.  The former points to a
    single instance of class Breakpoint.  The latter points to a
    list of such instances since there may be more than one
    breakpoint per line.

    i   i    c         C   s   | |  _  d  |  _ | |  _ | |  _ | |  _ | |  _ d |  _ d |  _	 d |  _
 t i |  _ t i d t _ |  i i |   |  i i | | f  o |  i | | f i |   n |  g |  i | | f <d  S(   Ni   i    (   RY   R   R   t   func_first_executable_lineRb   R   R@   RX   t   enabledt   ignoret   hitsR   t   nextR>   R`   RW   R[   RD   (   R   Rb   R   R@   RX   RY   (    (    R   R
     s    									c         C   sV   |  i |  i f } d  |  i |  i <|  i | i |   |  i | p |  i | =n d  S(   N(	   R   Rb   R   t   indexR   R`   R>   R[   R]   (   R   R   (    (    R   R\     s
    c         C   s   d |  _ d  S(   Ni   (   R   R   (   R   (    (    R   t   enable  s    c         C   s   d |  _ d  S(   Ni    (   R   R   (   R   (    (    R   t   disable  s    c         C   s   |  i o
 d } n d } |  i o | d } n | d } d |  i | |  i |  i f GH|  i o d |  i f GHn |  i o d |  i GHn |  i	 o6 |  i	 d j o
 d	 } n d
 } d |  i	 | f GHn d  S(   Ns   del  s   keep s   yes  s   no   s   %-4dbreakpoint   %s at %s:%ds   	stop only if %ss   	ignore next %d hitsi   Ry   t    s!   	breakpoint already hit %d time%s(   R   R@   t   dispR   R>   Rb   R   RX   R   R   t   ss(   R   R   R   (    (    R   t   bpprint  s     






 
(   R   R   R   R   R[   R   R`   R
   R\   R   R   R   (    (    (    R   R     s    				c         C   s   |  i p# |  i | i j o t Sn t Sn | i i |  i j o t Sn |  i	 p | i |  _	 n |  i	 | i j o t Sn t S(   s;   Check whether we should break here because of `b.funcname`.N(
   t   bRY   R   R%   R8   R5   R4   R6   Rz   R   (   R   R%   (    (    R   t   checkfuncname  s     

c         C   s*  t  i |  | f } xt d t |   D] } | | } | i	 d j o q) n t
 | |  p q) n | i d | _ | i p5 | i d j o | i d | _ q) q"| d f Sq) yX t | i | i | i  } | o2 | i d j o | i d | _ q| d f Sn Wq) | d f Sq) Xq) Wd S(   s   Determine which breakpoint for this file:line is to be acted upon.

    Called only if we know there is a bpt at this
    location.  Returns breakpoint that was triggered and a flag
    that indicates if it is ok to delete a temporary bp.

    i    i   N(   NN(   R   R[   Rb   R   t	   possiblest   rangeRr   Rs   R   R   R   R%   R   RX   R   R   t	   f_globalsR{   t   valR   (   Rb   R   R%   R   R   Rs   R   (    (    R   R;     s2      

t   Tdbc           B   s,   t  Z d   Z d   Z d   Z d   Z RS(   Nc         C   s.   | i i } | p
 d } n d G| G| GHd  S(   Ns   ???s   +++ call(   R%   R6   Rz   t   nameR|   (   R   R%   R|   R   (    (    R   R1   E  s     
c         C   sv   d  k  } | i i } | p
 d } n |  i | i i  } | i	 | | i
  } d G| G| i
 G| Gd G| i   GHd  S(   Ns   ???s   +++t   :(   R   R%   R6   Rz   R   R   R   R7   t   fnRU   R8   R   R   (   R   R%   R   R   R   R   (    (    R   R.   I  s    	 
c         C   s   d G| GHd  S(   Ns
   +++ return(   t   retval(   R   R%   R   (    (    R   R2   P  s    c         C   s   d G| GH|  i   d  S(   Ns   +++ exception(   t	   exc_stuffR   RS   (   R   R%   R   (    (    R   R3   R  s    	(   R   R   R1   R.   R2   R3   (    (    (    R   R   D  s   			c         C   s*   d G|  Gd GHt |  d  } d G| GHd  S(   Ns   foo(t   )i
   s   bar returned(   t   nt   bart   x(   R   R   (    (    R   t   fooV  s    c         C   s   d G|  Gd GH|  d S(   Ns   bar(R   i   (   t   a(   R   (    (    R   R   [  s    c          C   s   t    }  |  i d  d  S(   Ns   import bdb; bdb.foo(10)(   R   Rl   R   (   Rl   (    (    R   t   test_  s    	(   R   RN   R   R   t   __all__t	   ExceptionR    R   RR   R   R   R;   R   R   R   R   (   R   R;   R   R   R   RR   R   RN   R   R   R   R   R   R    (    (    R   t   ?   s   			 	R		5		