3
hʵ              8   @   s  d Z ddlmZ yeZW n ek
r,   Y nX ddlZddlZddlZddl	Z	ddl
Z
ddlZyeZeZW n ek
r   eZeZY nX yddlmZ dZW n ek
r4   dZyddlmZ W nl ek
r.   yddlmZ W nD ek
r(   yddlZW n  ek
r"   ddljZY nX Y nX Y nX Y nX yddlZddlZW n& ek
rp   dZejjd	 Y nX eed
rddlmZ nddl m!Z ddl"m#Z# dZ$dZ%e&e$e%dZ'ej( pdZ)dnddZ*dd Z+doddZ,dd Z-dd Z.G dd de/Z0G dd de/Z1G d d! d!e1Z2G d"d# d#e/Z3G d$d% d%e/Z4G d&d' d'ej5Z6G d(d) d)e6Z7G d*d+ d+e7Z8G d,d- d-ej9Z:G d.d/ d/e:Z;G d0d1 d1e:Z<G d2d3 d3e:Z=G d4d5 d5e/Z>e> Z?G d6d7 d7ej@e3ZAG d8d9 d9eAZBG d:d; d;eAZCG d<d= d=eAZDG d>d? d?e3e#jEZFG d@dA dAeAe#jGZHG dBdC dCeHe#jIZJG dDdE dEeJZKG dFdG dGeHZLG dHdI dIeHZMG dJdK dKeHZNG dLdM dMeAZOG dNdO dOeOZPG dPdQ dQeAZQG dRdS dSeAZRG dTdU dUeAZSG dVdW dWeAZTdXdY ZUG dZd[ d[eAZVG d\d] d]eVZWG d^d_ d_e/ZXG d`da daeAe#jYeXZZG dbdc dceAZ[G ddde deej\e3Z]G dfdg dge]Z^G dhdi diej\e3Z_G djdk dkej\e3eXZ`eF ZaeBjb Zcecea_cdldm Zded  dS )pz)
GDB extension that adds Cython support.
    )print_functionN)etreeTF)cElementTree)ElementTreez,Install pygments for colorized source code.
string_to_argv)r   )split)	libpythonCObjectPythonObject)r	   r
   zUTF-8c                s    fdd}|S )Nc                s   t j d fdd	}|S )Nc                sX   y|pt j }W n tk
r.   t jdY nX  rF|j d krFt | |f||S )NzNo frame is currently selected.)gdbselected_frameRuntimeErrorGdbErrornameNoFunctionNameInFrameError)selfframeargskwargs)errfunction k/var/www/html/CrowdFlow/Picklecon/ble_analysis_env/lib/python3.6/site-packages/Cython/Debugger/libcython.pywrapperI   s    z>default_selected_gdb_frame.<locals>.decorator.<locals>.wrapper)N)	functoolswraps)r   r   )r   )r   r   	decoratorH   s    
z-default_selected_gdb_frame.<locals>.decoratorr   )r   r   r   )r   r   default_selected_gdb_frameG   s    r   c                s   t j t fdd}|S )Nc                s6   |j dptj }| j|s&tjd | f||S )Nr   zHSelected frame does not correspond with a Cython function we know about.)getr   r   is_cython_functionr   )r   r   r   r   )r   r   r   r   Y   s    

z%require_cython_frame.<locals>.wrapper)r   r   require_running_program)r   r   r   )r   r   require_cython_frameX   s    r!   c                s    fdd}|S )Nc                s   t j  fdd}|S )Nc                sb   | j  }| j }|s|r0 r0| f|| n.|r@tj n| j rTtj  n
tjdd S )NzFNot a function cygdb knows about. Use the normal GDB commands instead.)r   is_python_functionr   executeis_relevant_functionr   )r   r   r   Zis_cyZis_py)	c_commandr   python_commandr   r   r   f   s    z5dispatch_on_frame.<locals>.decorator.<locals>.wrapper)r   r   )r   r   )r%   r&   )r   r   r   e   s    z$dispatch_on_frame.<locals>.decoratorr   )r%   r&   r   r   )r%   r&   r   dispatch_on_framed   s    r'   c                s   t j  fdd}|S )Nc                 s6   yt j  W n tk
r*   t jdY nX  | |S )NzNo frame is currently selected.)r   r   r   r   )r   r   )r   r   r   r   z   s
    z(require_running_program.<locals>.wrapper)r   r   )r   r   r   )r   r   r    y   s    r    c                s   t j  fdd}|S )Nc                s&   t |tjr|j } | |f||S )N)
isinstancer   Valuestring)r   r*   r   r   )r   r   r   r      s    z.gdb_function_value_to_unicode.<locals>.wrapper)r   r   )r   r   r   )r   r   gdb_function_value_to_unicode   s    r+   c               @   s   e Zd Zdd ZdS )CythonModulec             C   s.   || _ || _|| _i | _i | _i | _i | _d S )N)r   filename
c_filenameglobalslineno_cy2clineno_c2cy	functions)r   module_namer-   r.   r   r   r   __init__   s    zCythonModule.__init__N)__name__
__module____qualname__r4   r   r   r   r   r,      s   r,   c               @   s   e Zd Zdd ZdS )CythonVariablec             C   s&   || _ || _|| _|| _t|| _d S )N)r   cnamequalified_nametypeintlineno)r   r   r9   r:   r;   r=   r   r   r   r4      s
    zCythonVariable.__init__N)r5   r6   r7   r4   r   r   r   r   r8      s   r8   c                   s"   e Zd Zedf fdd	Z  ZS )CythonFunctionFalsec	       	         sF   t t| j||||| || _|| _|dk| _i | _g | _t | _	d S )NTrue)
superr>   r4   modulepf_cnameis_initmodule_functionlocals	argumentssetstep_into_functions)	r   rB   r   r9   rC   r:   r=   r;   rD   )	__class__r   r   r4      s    	
zCythonFunction.__init__)r5   r6   r7   r	   r4   __classcell__r   r   )rI   r   r>      s   r>   c               @   s   e Zd Zedddd Zedddd Ze dd Ze d	d
 Ze dd Ze dd Z	e dd Z
e dd Ze dd Zeddd!ddZdd Zdd Zd"ddZdd  ZdS )#
CythonBaseF)r   c             C   s   |j  | jjkS )N)r   cyfunctions_by_cname)r   r   r   r   r   r      s    zCythonBase.is_cython_functionc             C   s,   |j  dkr(tj|j }|o&|j  S dS )z
        Tells if a frame is associated with a Python function.
        If we can't read the Python frame information, don't regard it as such.
        PyEval_EvalFrameExF)r   r   Frameget_pyopis_optimized_out)r   r   pyframer   r   r   r"      s    zCythonBase.is_python_functionc             C   s   |j  S )N)r   )r   r   r   r   r   get_c_function_name   s    zCythonBase.get_c_function_namec             C   s
   |j  jS )N)find_salline)r   r   r   r   r   get_c_lineno   s    zCythonBase.get_c_linenoc             C   s$   | j jj|j }|d kr t |S )N)rL   rM   r   r   NoCythonFunctionInFrameError)r   r   resultr   r   r   get_cython_function   s    zCythonBase.get_cython_functionc             C   s    | j |}|jjj| j|dS )z
        Get the current Cython line number. Returns 0 if there is no
        correspondence between the C and Cython code.
        r   )rY   rB   r1   r   rV   )r   r   cyfuncr   r   r   get_cython_lineno   s    
zCythonBase.get_cython_linenoc             C   s   d  } }}| j |rZ| j|jj}| j|}||d ks>t|d }trtjjdd}n| j	|rt
j|j }|stjd|j }|j }trtjjdd}nB|j }| s|j rd }d}n"|jj }|j}trtjjdd}t|||fS )Nr      F)Zstripallz*Unable to read information on python frame)r   rY   rB   r-   r[   AssertionErrorpygmentsZlexersZCythonLexerr"   r   rO   rP   r   r   Zcurrent_line_numZPythonLexerrT   ZsymtabfullnamerU   ZCLexerSourceFileDescriptor)r   r   r-   r=   lexerZfilename_and_linenoZpyframeobjectZsymbol_and_line_objr   r   r   get_source_desc   s4    



zCythonBase.get_source_descc             C   s   | j  \}}|j|S )N)rb   
get_source)r   r   source_descr=   r   r   r   get_source_line  s    zCythonBase.get_source_linec             C   sN   |j  }|j }| j|s$| j|r(dS |rJ| j|rJ| j|}||jkS dS )zl
        returns whether we care about a frame on the user-level when debugging
        Cython code
        TF)r   olderr   r"   rY   rH   )r   r   r   Zolder_framecython_funcr   r   r   r$     s    

zCythonBase.is_relevant_functionc                s  t j } j  yj \}}W n  tk
rB   td|  dS X | rj rtj j	 }|dksr|j
 rj |ddS |j}d}	g }
nRj rƈj } fdd}|j}|j}	g }
nj \}} j }|}	g }
yt j|	}W n tk
r   d}Y n>X |j}t|tsJt|ttfs8t|}t|j d d}d	jd
d |
D }tjjd||||f  |jdk	rtjjd|j|f  tjjd ytjjd|j|  W n t jk
r   Y nX |j  dS )zk
        Print a C, Cython or Python stack frame and the line of source code
        if available.
        z%#%-2d Unknown Frame (compile with -g)NT)is_crN   c                s   j jj|  dS )N)r   )rL   	cy_cvalueinvoke)arg)r   r   r   r   <lambda>A  s    z-CythonBase.print_stackframe.<locals>.<lambda>r   z, c             s   s   | ]\}}d ||f V  qdS )z%s=%sNr   ).0r   valr   r   r   	<genexpr>X  s    z.CythonBase.print_stackframe.<locals>.<genexpr>z#%-2d 0x%016x in %s(%s)z	 at %s:%s
z    ) r   r   selectrb   r   printr"   r   rO   rP   rQ   print_stackframeco_namer   rY   r   r9   parse_and_evalr   addressr(   r<   strbytesr   joinsysstdoutwriter-   rc   r   )r   r   indexrh   r   rd   r=   rR   	func_nameZ
func_cname	func_argsrZ   fZ	gdb_valueZfunc_addressar   )r   r   r   rs   %  sV    


zCythonBase.print_stackframec             C   sT   t jd}yt jd}W n$ tk
r<   t jtjdY nX |j|j }|d S )NZ__pyx_mPyModuleObjectzy                Unable to lookup type PyModuleObject, did you compile python
                with debugging support (-g)?Zmd_dict)	r   ru   Zlookup_typer   r   textwrapdedentcastpointer)r   mr   r   r   r   get_remote_cython_globals_dictg  s    
z)CythonBase.get_remote_cython_globals_dictc             C   sF   | j  }tjj|}i }t }x"|j D ]\}}|||j|< q(W |S )zk
        Get the Cython globals dict where the remote names are turned into
        local strings.
        )r   r   ZPyObjectPtrZfrom_pyobject_ptrrG   	iteritemsZproxyval)r   Zremote_dictZpyobject_dictrX   seenkvr   r   r   get_cython_globals_dictu  s    z"CythonBase.get_cython_globals_dictN c             C   sT   t j|rd}nd|jf }|d kr:td||||f  ntd|||||f  d S )Nr   z(%s) z%s%s = %s%sz%s%-*s = %s%s)r   Zpretty_printer_lookupr;   rr   )r   r   valuemax_name_lengthprefixtypenamer   r   r   print_gdb_value  s    
zCythonBase.print_gdb_valuec             C   sV   |j | }| j d }d|jkrL||jkrH|jtkrDttj|jS dS dS ||jkS )Nr\   z->TF)	rE   r[   r9   r=   r;   r
   r<   r   ru   )r   rg   Z
local_namecyvarZ
cur_linenor   r   r   is_initialized  s    



zCythonBase.is_initialized)F)Nr   )r5   r6   r7   r   r   r"   rS   rV   rY   r[   rb   re   r$   rs   r   r   r   r   r   r   r   r   rK      s   	#A
rK   c               @   s8   e Zd ZdddZdd Zdd Zdd	 ZdddZdS )r`   Nc             C   s   || _ || _|| _d S )N)r-   ra   	formatter)r   r-   ra   r   r   r   r   r4     s    zSourceFileDescriptor.__init__c             C   s
   | j d k	S )N)r-   )r   r   r   r   valid  s    zSourceFileDescriptor.validc             C   sL   t rH| jrHtjrHtjj}| jd kr2t jj|d}n| j}t j	|| j|S |S )N)bg)
r^   ra   
parameterscolorize_codeterminal_backgroundr   r   
formattersZTerminalFormatterZ	highlight)r   coder   r   r   r   r   lex  s    
zSourceFileDescriptor.lexc             c   s   t | j}|r&|r&| j|j j }tj||d |d }xVt|D ]J\}}	|| |kr`d}
nd}
|rx| rx| j|	}	d|
|| |	j f V  qFW W d Q R X d S )Nr\   > z%s %4d    %s)	openr-   r   read
splitlines	itertoolsislice	enumeraterstrip)r   startstop
lex_source	mark_line
lex_entirer   sliceidxrU   r   r   r   r   _get_source  s    

z SourceFileDescriptor._get_sourceTr   Fc             C   sd   t jd}| js|t|d}|d kr.|d }ydj| j|||||S  tk
r^   |Y nX d S )NzUnable to retrieve source coder\   rp   )r   r   r-   maxry   r   IOError)r   r   r   r   r   r   excr   r   r   rc     s    

zSourceFileDescriptor.get_source)N)NTr   F)r5   r6   r7   r4   r   r   r   rc   r   r   r   r   r`     s   
 r`   c                   s    e Zd ZdZ fddZ  ZS )
CyGDBErrorz6
    Base class for Cython-command related errors
    c                s    |p
| j f}tt| j|  d S )N)msgrA   r   r4   )r   r   )rI   r   r   r4     s    zCyGDBError.__init__)r5   r6   r7   __doc__r4   rJ   r   r   )rI   r   r     s   r   c               @   s   e Zd ZdZdZdS )rW   z]
    raised when the user requests the current cython function, which is
    unavailable
    z7Current function is a function cygdb doesn't know aboutN)r5   r6   r7   r   r   r   r   r   r   rW     s   rW   c               @   s   e Zd ZdZdZdS )r   zi
    raised when the name of the C function could not be determined
    in the current C stack frame
    zDC function name could not be determined in the current C stack frameN)r5   r6   r7   r   r   r   r   r   r   r     s   r   c                   s.   e Zd ZdZd fdd	Zdd ZeZ  ZS )CythonParameterz*
    Base class for cython parameters
    Nc                s6   | j j | _| _tt| j||| |d k	r2|| _d S )N)rI   r   Zshow_docZset_docrA   r   r4   r   )r   r   command_classZparameter_classdefault)rI   r   r   r4     s
    zCythonParameter.__init__c             C   s
   t | jS )N)boolr   )r   r   r   r   __bool__  s    zCythonParameter.__bool__)N)r5   r6   r7   r   r4   r   __nonzero__rJ   r   r   )rI   r   r     s   r   c               @   s   e Zd ZdZdS ) CompleteUnqualifiedFunctionNameszH
    Have 'cy break' complete unqualified function or method names.
    N)r5   r6   r7   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdS )ColorizeSourceCodez5
    Tell cygdb whether to colorize source code.
    N)r5   r6   r7   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdS )TerminalBackgroundzJ
    Tell cygdb about the user's terminal background (light or dark).
    N)r5   r6   r7   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdd ZdS )CythonParametersz
    Simple container class that might get more functionality in the distant
    future (mostly to remind us that we're dealing with parameters).
    c             C   s@   t dtjtjd| _tdtjtjd| _tdtjtj	d| _
d S )NZcy_complete_unqualifiedTZcy_colorize_codeZcy_terminal_background_colorZdark)r   r   COMMAND_BREAKPOINTSZPARAM_BOOLEANcomplete_unqualifiedr   COMMAND_FILESr   r   ZPARAM_STRINGr   )r   r   r   r   r4   %  s    zCythonParameters.__init__N)r5   r6   r7   r   r4   r   r   r   r   r     s   r   c               @   s.   e Zd ZdZejZedd Zedd Z	dS )CythonCommandz(
    Base class for Cython commands
    c             C   s:   t | ds| || jf||S | || j| jf||S d S )Ncompleter_class)hasattrr   r   )clsclsnamer   r   r   r   r   	_registerB  s    
zCythonCommand._registerc             O   s0   t | dd }|r | j| j|| | j| j||S )Nalias)getattrr   r   r   )r   r   r   r   r   r   r   registerJ  s    zCythonCommand.registerN)
r5   r6   r7   r   r   COMMAND_NONEr   classmethodr   r   r   r   r   r   r   ;  s   r   c                   s0   e Zd ZdZdZejZejZ	 fddZ
  ZS )CyCyaa  
    Invoke a Cython command. Available commands are:

        cy import
        cy break
        cy step
        cy next
        cy run
        cy cont
        cy finish
        cy up
        cy down
        cy select
        cy bt / cy backtrace
        cy list
        cy print
        cy set
        cy locals
        cy globals
        cy exec
    rL   c                s   t t| j|||dd ttj tj tj tj t	j t
j tj tj tj tj tj tj tj tj tj tjddtj tj tdtdtdtdd	}x&|j D ]\}}| |_t| || qW | | _i | _i | _ i | _!t"j#t$| _%d S )
NT)r   zcy execz-cy-execcy_cnameri   	cy_linenocy_eval)import_Zbreak_stepnextruncontfinishupdownrq   Zbtlistprint_rE   r/   exec__execrG   r   ri   r   r   )&rA   r   r4   dictCyImportr   CyBreakCyStepCyNextCyRunCyContCyFinishCyUpCyDownCySelectCyBacktraceCyListCyPrintCyLocals	CyGlobalsr   ZFixGdbCommandCyExecCySetCyCNameCyCValueCyLineCyEvalitemsrL   setattrcython_namespacefunctions_by_qualified_namerM   collectionsdefaultdictr   functions_by_name)r   r   r   r   commandscommand_namecommand)rI   r   r   r4   n  sB    

zCyCy.__init__)r5   r6   r7   r   r   r   r   r   ZCOMPLETE_COMMANDr   r4   rJ   r   r   )rI   r   r   S  s
   r   c               @   s.   e Zd ZdZdZejZejZ	e
jdd ZdS )r   zb
    Import debug information outputted by the Cython compiler
    Example: cy import FILE...
    z	cy importc             C   s<  t |tr|jt}x t|D ]}yt|}W n: tk
rl } ztjd||j	d f W Y d d }~X nX t
j|}x|j D ]}tf |j}|| jj|j< x,|jdD ]}	|	j}
tf |
|j|
d < qW x|jdD ]}tf d|i|j}|j}|j}| jj| j| || jj|j< || jj|j< | }
|j|< x.|jdD ] }|j}
tf |
|j|
d < qJW x*|jdD ]}|j}
|jj|
d  qzW |j j!d	d
 |jdD  qW xt|jdD ]f}t"|jd }|jd }t#t$t"|jd j% }t&||j'||f< x|D ]}||f|j(|< qW qW qW q W d S )NzUnable to open file %r: %sr\   ZGlobalsr   Z	FunctionsrB   ZLocalsZStepIntoFunctionsc             s   s   | ]}|j V  qd S )N)tag)rm   Zfuncargr   r   r   ro     s    z"CyImport.invoke.<locals>.<genexpr>	ArgumentsZLineNumberMapping
src_linenosrc_path	c_linenos))r(   BYTESdecode_filesystemencodingr   r   OSErrorr   r   r   r   parsegetrootr,   attribrL   r   r   findr8   r/   r>   r:   r   appendr   rM   r9   r2   rE   rH   addrF   extendr<   r   mapr   minr0   r1   )r   r   from_ttyrk   r   etrB   cython_modulevariabledr   cython_functionr   qnamelocalZstep_into_funcmarkerr   r  r  c_linenor   r   r   rj     sL    

*




zCyImport.invokeN)r5   r6   r7   r   r   r   ZCOMMAND_STATUSr   ZCOMPLETE_FILENAMEr   r   dont_suppress_errorsrj   r   r   r   r   r     s
   r   c               @   sF   e Zd ZdZdZejZdd Zdd Z	e
jdd Ze
jd	d
 ZdS )r   a  
    Set a breakpoint for Cython code using Cython qualified name notation, e.g.:

        cy break cython_modulename.ClassName.method_name...

    or normal notation:

        cy break function_or_method_name...

    or for a line number:

        cy break cython_module:lineno...

    Set a Python breakpoint:
        Break on any function or method named 'func' in module 'modname'

            cy break -p modname.func...

        Break on any function or method named 'func'

            cy break -p func...
    zcy breakc             C   s   |j d\}}}t|}|r*| jj| }n
| j j}|j|f|jkrr|j|j|f }d|j|f }t	j
d|  n
t	jdd S )N:z%s:%szbreak z5Not a valid line number. Does it contain actual code?)	partitionr<   rL   r   rY   rB   r-   r0   r.   r   r#   r   )r   r   
modulename_r=   r  r  Z
breakpointr   r   r   
_break_pyx  s    
zCyBreak._break_pyxc             C   sx  | j jj|}|r|jrd }|g}|s<| j jj|p8g }dd |D }|s^tjd|  d S t|dkr2td x&t	|D ]\}}td||j
f  q~W xytd}W n tk
r   d S X |j dkrd S |j d	kr|}P q|j r$d
t|  ko
t|k n  r$|t| g}P qtd qW n
|d
 g}x6|D ].}tjd|j  |jrBtjd|j  qBW d S )Nc             S   s   g | ]}|j s|qS r   )rD   )rm   r   r   r   r   
<listcomp>  s    z+CyBreak._break_funcname.<locals>.<listcomp>zbreak r\   z"There are multiple such functions:z%3d) %szMSelect a function, press 'a' for all functions or press 'q' or '^D' to quit: qr   r   zNot understood...zbreak %s)rL   r   r   rD   r   r   r#   lenrr   r   r:   inputEOFErrorlowerisdigitr<   r9   rC   )r   funcnamefuncZbreak_funcsfuncsr   rX   r   r   r   _break_funcname  sF    


$

zCyBreak._break_funcnamec             C   s   t |tr|jt}t|}|jdr8|dd  }d}nd}x>|D ]6}|rZtjd|  qBd|krn| j| qB| j	| qBW d S )Nz-pr\   TFzpy-break %sr  )
r(   r  r  r  r   
startswithr   r#   r   r+  )r   Zfunction_namesr  argvZpython_breakpointsr(  r   r   r   rj   B  s    



zCyBreak.invokec                s   dd | j jj D }dd | j jj D }tjr@tj||}n|}|j j	 }| sbd|d	 krt
|d t  j	 fdd|D S |d
   fdd|D }t tkrt t fdd|D }|S )Nc             S   s&   g | ]\}}t d d |D r|qS )c             s   s   | ]}|j  V  qd S )N)rD   )rm   r   r   r   r   ro   Z  s    z.CyBreak.complete.<locals>.<listcomp>.<genexpr>)any)rm   nLr   r   r   r!  Y  s    z$CyBreak.complete.<locals>.<listcomp>c             S   s   g | ]\}}|j s|qS r   )rD   )rm   r/  r   r   r   r   r!  [  s    .r\   c                s"   g | ]}|j r| kr|qS r   )r,  )rm   r/  )r   wordr   r   r!  g  s    c                s   g | ]}|j  r|qS r   )r,  )rm   r/  )lastwordr   r   r!  l  s    c                s   g | ]}| d  qS )Nr   )rm   r/  )strip_prefix_lengthr   r   r!  r  s    r5  )rL   r   r   r   r   r   r   chainstripr   rG   r#  )r   textr2  namesqnamesZ	all_nameswordsZcomplr   )r3  r   r4  r2  r   completeU  s    zCyBreak.completeN)r5   r6   r7   r   r   r   r   r   r   r+  r   r  rj   r<  r   r   r   r   r     s   1r   c                   sH   e Zd ZdZ fddZ fddZ fddZdd	 Zd
d Z  Z	S )
CythonInfozM
    Implementation of the interface dictated by libpython.LanguageInfo.
    c                s(   | j |r| j|d S tt| j|S )Nr\   )r   r[   rA   r=  r=   )r   r   )rI   r   r   r=   |  s    
zCythonInfo.linenoc                s<   yt t| j|}W n tjk
r*   d S X |j p6d S d S )N)rA   r=  re   r   r   r7  )r   r   rU   )rI   r   r   re     s
    zCythonInfo.get_source_linec                s   | j rtt| j|S d S )N)r"   rA   r=  exc_info)r   r   )rI   r   r   r>    s    zCythonInfo.exc_infoc             C   s   | j  r| j jS f S )N)r   rY   rH   )r   r   r   r   runtime_break_functions  s    
z"CythonInfo.runtime_break_functionsc             C   s   dg}|j | jj |S )NrN   )r  rL   rM   )r   rX   r   r   r   static_break_functions  s    z!CythonInfo.static_break_functions)
r5   r6   r7   r   r=   re   r>  r?  r@  rJ   r   r   )rI   r   r=  w  s   	r=  c               @   s   e Zd Zedd ZdS )CythonExecutionControlCommandc             C   s   | | j tS )N)r   cython_info)r   r   r   r   r     s    z&CythonExecutionControlCommand.registerN)r5   r6   r7   r   r   r   r   r   r   rA    s   rA  c               @   s&   e Zd ZdZdZdZejdd ZdS )r   z&Step through Cython, Python or C code.zcy -stepTc             C   sV   | j  r| j| j n<| j sD| jr*d}nd}| jtj|dd n| j| jd d S )Nr   r   T)	to_string)stepinto)r"   Zpython_steprD  r   Zfinish_executingr   r#   r   )r   r   r  r   r   r   r   rj     s    zCyStep.invokeN)	r5   r6   r7   r   r   rD  r   r  rj   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdZdZdS )r   z#Step-over Cython, Python or C code.zcy -nextFN)r5   r6   r7   r   r   rD  r   r   r   r   r     s   r   c               @   s    e Zd ZdZdZejejZ	dS )r   z
    Run a Cython program. This is like the 'run' command, except that it
    displays Cython or Python source lines as well
    zcy runN)
r5   r6   r7   r   r   r   r  rA  r   rj   r   r   r   r   r     s   r   c               @   s    e Zd ZdZdZejejZ	dS )r   z
    Continue a Cython program. This is like the 'run' command, except that it
    displays Cython or Python source lines as well.
    zcy contN)
r5   r6   r7   r   r   r   r  rA  r   rj   r   r   r   r   r     s   r   c               @   s    e Zd ZdZdZejejZ	dS )r   z-
    Execute until the function returns.
    z	cy finishN)
r5   r6   r7   r   r   r   r  rA  r   rj   r   r   r   r   r     s   r   c               @   s&   e Zd ZdZdZdZejdd ZdS )r   z5
    Go up a Cython, Python or relevant C frame.
    zcy upr   c             G   s   y8t j| jdd x"| jt j s4t j| jdd qW W n. tk
rf } zt j|j W Y d d }~X nX t j }d}x|r|j }|d7 }qvW | j	|d d d S )NT)rC  r   r\   )r}   )
r   r#   _commandr$   r   r   r   r   rf   rs   )r   r   r  r   r}   r   r   r   rj     s    zCyUp.invokeN)	r5   r6   r7   r   r   rE  r   r  rj   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdZdZdS )r   z7
    Go down a Cython, Python or relevant C frame.
    zcy downr   N)r5   r6   r7   r   r   rE  r   r   r   r   r     s   r   c               @   s"   e Zd ZdZdZejdd ZdS )r   z
    Select a frame. Use frame numbers as listed in `cy backtrace`.
    This command is useful because `cy backtrace` prints a reversed backtrace.
    z	cy selectc             C   s   yt |}W n$ tk
r0   tjd|f Y nX tj }x|j rN|j }q<W tj|}ytjd|| d f  W n. t	k
r } ztj|j
 W Y d d }~X nX d S )NzNot a valid number: %rz	select %dr\   )r<   
ValueErrorr   r   r   newerr   
stackdepthr#   r   r   )r   Zstacknor  r   rH  r  r   r   r   rj     s    

zCySelect.invokeN)r5   r6   r7   r   r   r   r  rj   r   r   r   r   r      s   r   c               @   s6   e Zd ZdZdZdZejZej	Z
ejedd ZdS )r   zPrint the Cython stackzcy btzcy backtracec             C   s   t j }x|j r|j }q
W |dk}d}xT|r~y| j|}W n tk
rV   d}Y nX |s`|rl| j|| |d7 }|j }q,W d S )Nz-ar   Fr\   )r   r   rf   r$   r   rs   rG  )r   r   r  r   Z	print_allr}   Zis_relevantr   r   r   rj   #  s    

zCyBacktrace.invokeN)r5   r6   r7   r   r   r   r   COMMAND_STACKr   COMPLETE_NONEr   r   r  r    rj   r   r   r   r   r     s   r   c               @   s.   e Zd ZdZdZejZejZ	e
jdd ZdS )r   za
    List Cython source code. To disable to customize colouring see the cy_*
    parameters.
    zcy listc             C   s2   | j  \}}|j|d |d |dd}t| d S )N   T)r   r   )rb   rc   rr   )r   r  r  sdr=   sourcer   r   r   rj   E  s    zCyList.invokeN)r5   r6   r7   r   r   r   r   r   rJ  r   r   r  rj   r   r   r   r   r   ;  s
   r   c               @   s0   e Zd ZdZdZejZej	dd Z
dd ZdS )r   zT
    Print a Cython variable using 'cy-print x' or 'cy-print module.function.x'
    zcy printc             C   s  | j  }| j jj}||kr>|| jtj}td||f  n||kr|| j}yt	j
|}W n  tk
r~   td|  Y n"X |js| j|| ntd|  nr| j rt	jd| S | j r| jjj|jd}x |D ]}|dkr|j }qP qW | j|| nt	jd|  d S )Nz%s = %szunable to get value of %sz%s is optimized outz	py-print *zprint )r   rY   rB   r/   get_truncated_reprr   MAX_OUTPUT_LENrr   r9   r   ru   r   rQ   r   r"   r#   r   rL   ri   rj   lstripdereference)r   r   r  global_python_dictmodule_globalsr   r9   cr   r   r   rj   V  s0    



zCyPrint.invokec             C   s,   | j  r$| j }ttj|j|jS g S d S )N)r   rY   r   r   r6  rE   r/   )r   r   r   r   r   r<  y  s    zCyPrint.completeN)r5   r6   r7   r   r   r   COMMAND_DATAr   r   r  rj   r<  r   r   r   r   r   N  s
   #r   c             C   s   | d j  S )Nr   )r&  )itemr   r   r   rl     s    rl   c               @   s:   e Zd ZdZdZejZejZ	e
jeddddd ZdS )	r   z8
    List the locals from the current Cython frame.
    z	cy localszinfo localsz	py-locals)r%   r&   c       	      C   s   | j  }|jr"| jjj|| d S |j}tt|td}xRt|j	 t
dD ]>\}}| j| j  |jrJtj|j}|jsJ| j|j||d qJW d S )N)keyr   )rY   rD   rL   r/   rj   rE   r#  r   sortedr   sortkeyr   r   r   ru   r9   rQ   r   )	r   r   r  r  Zlocal_cython_varsr   r   r   r   r   r   r   rj     s    
zCyLocals.invokeN)r5   r6   r7   r   r   r   rI  r   rJ  r   r   r  r'   rj   r   r   r   r   r     s   r   c               @   s:   e Zd ZdZdZejZejZ	e
jeddddd ZdS )	r   z:
    List the globals from the current Cython module.
    z
cy globalszinfo variablesz
py-globals)r%   r&   c             C   s  | j  }| j jj}d}d}|r0tt|td}|r@tt|}t||}t }td xDt|j	 t
dD ]0\}	}
|
jtj}
|j|	 td||	|
f  qjW td xbt|j	 t
dD ]N\}}||krytj|j}W n tk
r   Y qX |js| j|j||d qW d S )Nr   )rX  zPython globals:z    %-*s = %sz
C globals:z    )r   rY   rB   r/   r#  r   rG   rr   rY  r   rZ  rO  r   rP  r  r   ru   r9   r   rQ   r   r   )r   r   r  rS  rT  Zmax_globals_lenZmax_globals_dict_lenr   r   r   r   r   r   r   r   r   r   rj     s2    


zCyGlobals.invokeN)r5   r6   r7   r   r   r   rI  r   rJ  r   r   r  r'   rj   r   r   r   r   r     s   r   c               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )EvaluateOrExecuteCodeMixinz
    Evaluate or execute Python code in a Cython or Python frame. The 'evalcode'
    method evaluations Python code, prints a traceback if an exception went
    uncaught, and returns any return value as a gdb.Value (NULL on exception).
    c       	      C   s   | j  }x|jj D ]\}}|jtkr| j||rytj|j}W n t	k
rX   wY n
X |j
rbq|j|}d|||jf }z&tj|dk rtjd tjdW d|j| X qW dS )zBFill a remotely allocated dict with values from the Cython C stackz
                    (PyObject *) PyDict_SetItem(
                        (PyObject *) %d,
                        (PyObject *) %d,
                        (PyObject *) %s)
                r   zPyErr_Print()zUnable to execute Python code.N)rY   rE   r   r;   r
   r   r   ru   r9   r   rQ   Zalloc_pystringr   xdecref)	r   executorZlocal_dict_pointerrg   r   r   rn   Z	pystringpr   r   r   r   _fill_locals_dict  s"    


z,EvaluateOrExecuteCodeMixin._fill_locals_dictc             C   sH   t j }x0|r8| j|s"| j|r.|j  |S |j }q
W t jdd S )Nz0There is no Cython or Python frame on the stack.)r   r   r   r"   rq   rf   r   )r   r   r   r   r   "_find_first_cython_or_python_frame  s    

z=EvaluateOrExecuteCodeMixin._find_first_cython_or_python_framec             C   sf   t j T tjd}tjd}z&| j|t j| |j||||}W d |jt j| X W d Q R X |S )Nz&(PyObject *) PyModule_GetDict(__pyx_m)z(PyObject *) PyDict_New())r   ZFetchAndRestoreErrorr   ru   r^  Zpointervalueevalcoder\  )r   r]  r   
input_typeZglobal_dictZ
local_dictrX   r   r   r   _evalcode_cython   s    



z+EvaluateOrExecuteCodeMixin._evalcode_cythonc             C   s6   | j  }tj }| j|r(tj|||S | j|||S )zi
        Evaluate `code` in a Python or Cython stack frame using the given
        `input_type`.
        )r_  r   PythonCodeExecutorr"   Z_evalcode_pythonrb  )r   r   ra  r   r]  r   r   r   r`    s
    
z#EvaluateOrExecuteCodeMixin.evalcodeN)r5   r6   r7   r   r^  r_  rb  r`  r   r   r   r   r[    s
    r[  c               @   s.   e Zd ZdZdZejZejZ	e
jdd ZdS )r   zD
    Execute Python code in the nearest Python or Cython frame.
    z-cy-execc             C   s.   | j |\}}tj }|j| j||j d S )N)Zreadcoder   rc  r\  r`  ZPy_file_input)r   exprr  ra  r]  r   r   r   rj   '  s    zCyExec.invokeN)r5   r6   r7   r   r   r   rI  r   rJ  r   r   r  rj   r   r   r   r   r     s
   r   c               @   s2   e Zd ZdZdZejZejZ	e
jedd ZdS )r   z
    Set a Cython variable to a certain value

        cy set my_cython_c_variable = 10
        cy set my_cython_py_variable = $cy_eval("{'doner': 'kebab'}")

    This is equivalent to

        set $cy_value("my_cython_variable") = 10
    zcy setc             C   sR   |j dd}t|dkr"tjd|\}}| jjj|j }tjd||f  d S )N=r\      z,Invalid expression. Use 'cy set var = expr'.zset %s = %s)	r   r#  r   r   rL   r   rj   r7  r#   )r   rd  r  Zname_and_exprvarnamer9   r   r   r   rj   >  s    
zCySet.invokeN)r5   r6   r7   r   r   r   rV  r   rJ  r   r   r  r!   rj   r   r   r   r   r   .  s   
r   c               @   s(   e Zd ZdZejeedddZdS )r   z
    Get the C name of a Cython variable in the current context.
    Examples:

        print $cy_cname("function")
        print $cy_cname("Class.method")
        print $cy_cname("module.function")
    Nc             C   s   |p
t j }d }| j|r| j|}||jkr<|j| j}nF||jjkrX|jj| j}n*d|jj|f }||jj	kr|jj	| j}|s| j
jj|}|st jd| |S )Nz%s.%szNo such Cython variable: %s)r   r   r   rY   rE   r9   rB   r/   r   r2   rL   r   r   r   )r   cynamer   r9   r  r  r   r   r   rj   V  s     


zCyCName.invoke)N)	r5   r6   r7   r   r   r  r!   r+   rj   r   r   r   r   r   L  s
   r   c                   s0   e Zd ZdZejeed fdd	Z  Z	S )r   z-
    Get the value of a Cython variable.
    Nc                s`   | j  }| j|}| j||r<tt| j||d}tj|S ||krN|| jS tj	d| d S )N)r   zVariable %s is not initialized.)
r   rY   r   rA   r   rj   r   ru   Z_gdbvalr   )r   rh  r   Zglobals_dictr  r9   )rI   r   r   rj   v  s    


zCyCValue.invoke)N)
r5   r6   r7   r   r   r  r!   r+   rj   rJ   r   r   )rI   r   r   q  s
   r   c               @   s"   e Zd ZdZejedd ZdS )r   z&
    Get the current Cython line.
    c             C   s   | j  d S )Nr\   )r[   )r   r   r   r   rj     s    zCyLine.invokeN)r5   r6   r7   r   r   r  r!   rj   r   r   r   r   r     s   r   c               @   s"   e Zd ZdZejedd ZdS )r   zO
    Evaluate Python code in the nearest Python or Cython frame and return
    c             C   s   t jj}| j||S )N)r   rc  ZPy_eval_inputr`  )r   Zpython_expressionra  r   r   r   rj     s    zCyEval.invokeN)r5   r6   r7   r   r   r  r+   rj   r   r   r   r   r     s   r   c               C   s    t jtjdtjtjf  d S )Nz        define cy step
        cy -step
        end

        define cy next
        cy -next
        end

        document cy step
        %s
        end

        document cy next
        %s
        end
    )r   Zsource_gdb_scriptr   r   r   r   r   r   r   r   r   register_defines  s    ri  )T)N)er   
__future__r   	raw_inputr$  	NameErrorrz   r   r   r   r   r   unicodeUNICODErw   r  rx   lxmlr   Z	have_lxmlImportErrorZ	xml.etreer   r   Zelementtree.ElementTreeZpygments.lexersr^   Zpygments.formattersstderrr|   r   r   shlexr   ZCython.Debuggerr   r	   r
   r   Z_data_typesgetfilesystemencodingr  r   r!   r'   r    r+   objectr,   r8   r>   rK   r`   r   r   rW   r   	Parameterr   r   r   r   r   r   Commandr   r   r   r   Z
PythonInfor=  ZExecutionControlCommandBaserA  ZPythonStepperMixinr   r   r   r   r   r   r   r   r   r   r   rZ  r   r   r[  ZPyExecr   r   ZFunctionr   r   r   r   rB  r   rL   ri  r   r   r   r   <module>   s   
"


 ]?
QB %
		 3-Q%