ó
¦V]c           @   s    d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z e j	 e
 ƒ Z d e d „ Z d Z d d e d „ Z d S(   s  
The Cython debugger

The current directory should contain a directory named 'cython_debug', or a
path to the cython project directory should be given (the parent directory of
cython_debug).

Additional gdb args can be provided only if a path to the project directory is
given.
iÿÿÿÿNt    c         C   sK  | s\ t  j j |  d d ƒ } t j | ƒ } | s\ t j d t t  j j |  ƒ f ƒ q\ n  t j	 ƒ  \ } } t  j
 | d ƒ } z¹ | j | ƒ | j t j d ƒ ƒ | r¯ n‰ t  j j |  d d ƒ } t | ƒ }	 z |	 j ƒ  }
 Wd  |	 j ƒ  X| j d |
 ƒ | j d j d	 „  | Dƒ ƒ ƒ | j t j d
 ƒ ƒ Wd  | j ƒ  X| S(   Nt   cython_debugs   cython_debug_info_*s.   %s.
No debug files were found in %s. Aborting.t   wsV              # This is a gdb command file
            # See https://sourceware.org/gdb/onlinedocs/gdb/Command-Files.html

            set breakpoint pending on
            set print pretty on

            python
            # Activate virtualenv, if we were launched from one
            import os
            virtualenv = os.getenv('VIRTUAL_ENV')
            if virtualenv:
                path_to_activate_this_py = os.path.join(virtualenv, 'bin', 'activate_this.py')
                print("gdb command file: Activating virtualenv: %s; path_to_activate_this_py: %s" % (
                    virtualenv, path_to_activate_this_py))
                with open(path_to_activate_this_py) as f:
                    exec(f.read(), dict(__file__=path_to_activate_this_py))

            from Cython.Debugger import libcython, libpython
            end
            t   interpreters   file %s
s   
c         s   s   |  ] } d  | Vq d S(   s   cy import %s
N(    (   t   .0t   fn(    (    s4   lib/python2.7/site-packages/Cython/Debugger/Cygdb.pys	   <genexpr>J   s    s°                  python
                import sys
                try:
                    gdb.lookup_type('PyModuleObject')
                except RuntimeError:
                    sys.stderr.write(
                        'Python was not compiled with debug symbols (or it was '
                        'stripped). Some functionality may not work (properly).\n')
                end

                source .cygdbinit
            (   t   ost   patht   joint   globt   syst   exitt   usaget   abspatht   tempfilet   mkstempt   fdopent   writet   textwrapt   dedentt   opent   readt   close(   t   path_to_debug_infot   prefix_codet	   no_importt   patternt   debug_filest   fdt   tempfilenamet   fR   t   interpreter_fileR   (    (    s4   lib/python2.7/site-packages/Cython/Debugger/Cygdb.pyt   make_command_file   s6    		 
 s0   Usage: cygdb [options] [PATH [-- GDB_ARGUMENTS]]c         C   sž  t  j d t ƒ } | j d d d d d d d ƒ| j d d	 d d
 d d d d d d ƒ| j ƒ  \ } } |  d k r¢ t | ƒ d k r– | d }  q¢ t j }  n  | d k r» | d } n  |  d k rÐ t	 } n  t
 j } | j d k rô t
 j } n  | j d k rt
 j } n  t
 j d | ƒ t j d | j ƒ t j d | | ƒ t j d |  | ƒ t |  d | ƒ} t j d | j | | ƒ t | ƒ Ü } t j d | | j ƒ  ƒ t j d | j ƒ t j | j d | g | ƒ }	 t j d | j |	 j ƒ xX t	 rPy9 t j d |	 j ƒ |	 j ƒ  }
 t j d |	 j |
 ƒ Wn t k
 rKqùXPqùWt j d | j ƒ  ƒ Wd QXt j d  | ƒ t j | ƒ t j d! | ƒ d S("   sb  
    Start the Cython debugger. This tells gdb to import the Cython and Python
    extensions (libcython.py and libpython.py) and it enables gdb's pending
    breakpoints.

    path_to_debug_info is the path to the Cython build directory
    gdb_argv is the list of options to gdb
    no_import tells cygdb whether it should import debug information
    R   s   --gdb-executablet   destt   gdbt   defaultt   helps$   gdb executable to use [default: gdb]s	   --verboses   -vt	   verbosityt   actiont   counti    s8   Verbose mode. Multiple -v options increase the verbosityi   s   --i   t   levels   verbosity = %rs   options = %r; args = %rsI   Done parsing command-line options. path_to_debug_info = %r, gdb_argv = %rR   s3   Launching %s with command file: %s and gdb_argv: %ss%   Command file (%s) contains: """
%s"""s   Spawning %s...s   -commands   Spawned %s (pid %d)s#   Waiting for gdb (pid %d) to exit...s3   Wait for gdb (pid %d) to exit is done. Returned: %rs%   Closing temp command file with fd: %sNs   Removing temp command file: %ss   Removed temp command file: %s(   t   optparset   OptionParserR   t
   add_optiont
   parse_argst   Nonet   lenR   t   curdirt   Truet   loggingt   WARNR%   t   INFOt   DEBUGt   basicConfigt   loggert   infot   debugR    R"   R   R   t
   subprocesst   Popent   pidt   waitt   KeyboardInterruptt   filenot   remove(   R   t   gdb_argvR   t   parsert   optionst   argst   logging_levelR   R   t   pt   ret(    (    s4   lib/python2.7/site-packages/Cython/Debugger/Cygdb.pyt   main_   s\    
			
		(   t   __doc__R   R
   R	   R   R   R9   R)   R1   t	   getLoggert   __name__R6   t   FalseR    R   R-   RG   (    (    (    s4   lib/python2.7/site-packages/Cython/Debugger/Cygdb.pyt   <module>   s   D