o
    wi1                     @   sh   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	e
Z		d	ddZdd ZdS )
a  
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.
    N Fc                 C   s.  |st j| dd}t|}|stdt j|   t \}}t 	|d}zi|
| |
tdtt d  |r?nL|sdt j| dd}	t|	}
z
|
 }W |
  n|
  w |
d|  |
d	d
d |D  |s|
td| d  |
d W |  |S W |  |S |  w )Ncython_debugzcython_debug_info_*z1No cython debug files were found in %s. Aborting.wa              # 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
            try:
                # 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
            except Exception as ex:
                from traceback import print_exc
                print("There was an error in Python code originating from the file z")
                print("It used the Python interpreter " + str(sys.executable))
                print_exc()
                exit(1)
            end
            interpreterzfile %s

c                 s   s    | ]}d | V  qdS )zcy import %s
N ).0fnr   r   R/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/Cython/Debugger/Cygdb.py	<genexpr>V   s    z$make_command_file.<locals>.<genexpr>a%                      python
                    import sys
                    # Check if the Python executable provides a symbol table.
                    if not hasattr(gdb.selected_inferior().progspace, "symbol_file"):
                        sys.stderr.write(
                            "z was not compiled with debug symbols (or it was "
                            "stripped). Some functionality may not work (properly).\n")
                    end
                zsource .cygdbinit
)ospathjoinglobsysexitabspathtempfilemkstempfdopenwritetextwrapdedentstr__file__openreadclose)path_to_debug_infoprefix_code	no_importskip_interpreterpatterndebug_filesfdtempfilenamefr   interpreter_filer   r   r   r
   make_command_file   sT   






r(   c               	   C   s&  t jddd} | jdddd | jdd	d
dd | jddddd | jddddddd | jdddddd |  }|j}|j}|d
u }|jd
u rl|rltj|d rldd
l	}|jdd
 }|jd }|
d| d tj}|jdkrwtj}|jd krtj}tj|d! |j}td"| t|||d#}td$|j|| t|V}	td%||	  td&|j t|jd'|g| }
td(|j|
j 	 ztd*|
j |
 }td+|
j| W n	 ty   Y nw nqtd,|	  W d
   n1 sw   Y  td-| t| td.| d
S )/z
    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.
    cygdbzCython debugger)progdescriptiongdb_argv*z/Arguments to forward to gdb; specified after --)nargshelpz--build-dir	build_dirNz(Directory containing cython_build/ files)destdefaultr/   z--gdb-executablegdbz$gdb executable to use [default: gdb]z	--verbosez-v	verbositycountr   z8Verbose mode. Multiple -v options increase the verbosity)r1   actionr2   r/   z--skip-interpreterr!   F
store_truez]Do not automatically point GDB to the same interpreter used to generate debugging information)r1   r2   r6   r/      zPUsing deprecated positional parameter to find build directory. Use "--build-dir z" argument instead.   )levelzoptions = %r)r    r!   z3Launching %s with command file: %s and gdb_argv: %sz%Command file (%s) contains: """
%s"""zSpawning %s...z-commandzSpawned %s (pid %d)Tz#Waiting for gdb (pid %d) to exit...z3Wait for gdb (pid %d) to exit is done. Returned: %rz%Closing temp command file with fd: %szRemoving temp command file: %szRemoved temp command file: %s) argparseArgumentParseradd_argument
parse_argsr0   r,   r   r   isdirwarningswarnloggingWARNr4   INFODEBUGbasicConfigr!   loggerdebugr(   infor3   r   r   
subprocessPopenpidwaitKeyboardInterruptfilenoremove)parseroptionsr   r,   r    r@   logging_levelr!   r%   r   pretr   r   r
   maink   s   




	
rV   )r   FF)__doc__r   r   r   r   r   rJ   r;   rB   	getLogger__name__rG   r(   rV   r   r   r   r
   <module>   s   

Q