
    Aew                         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dZdZddZy)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.
    Nc                    |stt         j                  j                  | dd      }t        j                  |      }|s<t	        j
                  t        dt         j                  j                  |       d       t        j                         \  }}t        j                  |d      }	 |j                  |       |j                  t        j                  d             |rnt         j                  j                  | dd      }t        |      }		 |	j                         }
|	j!                          |j                  d|
z         |j                  d	j                  d
 D                     |j                  t        j                  d             |j!                          |S # |	j!                          w xY w# |j!                          w xY w)Ncython_debugzcython_debug_info_*z.
No debug files were found in z. Aborting.waV              # 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
            interpreterzfile %s

c              3   &   K   | ]	  }d |z    yw)zcy import %s
N ).0fns     5lib/python3.12/site-packages/Cython/Debugger/Cygdb.py	<genexpr>z$make_command_file.<locals>.<genexpr>J   s     J.3Js   a                  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
            )ospathjoinglobsysexitusageabspathtempfilemkstempfdopenwritetextwrapdedentopenreadclose)path_to_debug_infoprefix_code	no_importpatterndebug_filesfdtempfilenamefr   interpreter_filer   s              r   make_command_filer(      sj   '',,1-46 ii(HH#("''//:L*MO P  '')B
		"cA3		 !  	,  77<< 2NMRD#Dz).335 &&(GGK+-.GGDIIJkJJKGGHOO %   	
	' !&&(" 	
	s&   %A$F0 
F A/F0 F--F0 0Gz0Usage: cygdb [options] [PATH [-- GDB_ARGUMENTS]]c                    t        j                  t              }|j                  dddd       |j                  dddd	d
d       |j	                         \  }}| $t        |      dkD  r|d
   } nt        j                  } ||dd }| dk(  rd}t        j                  }|j                  dk(  rt        j                  }|j                  dk\  rt        j                  }t        j                  |       t        j                  d|j                         t        j!                  d||       t        j!                  d| |       t#        | |      }t        j                  d|j$                  ||       t'        |      5 }t        j!                  d| |j(                                t        j                  d|j$                         t+        j,                  |j$                  d|g|z         }	t        j                  d|j$                  |	j.                         	 	 t        j!                  d|	j.                         |	j1                         }
t        j!                  d|	j.                  |
       	 t        j!                  d |j4                                ddd       t        j!                  d|       t        j6                  |       t        j!                  d |       y# t2        $ r Y nw xY w# 1 sw Y   [xY w)!ab  
    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   z--gdb-executablegdbz$gdb executable to use [default: gdb])destdefaulthelpz	--verbosez-v	verbositycountr   z8Verbose mode. Multiple -v options increase the verbosity)r+   actionr,   r-   N   z--T   )levelzverbosity = %rzoptions = %r; args = %rzIDone parsing command-line options. path_to_debug_info = %r, gdb_argv = %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)z#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)optparseOptionParserr   
add_option
parse_argslenr   curdirloggingWARNr.   INFODEBUGbasicConfigloggerinfodebugr(   r*   r   r   
subprocessPopenpidwaitKeyboardInterruptfilenoremove)r   gdb_argvr!   parseroptionsargslogging_levelr%   r   prets              r   mainrP   _   s~    ""/F
(E3  5 k4!G  I '')OWd!t9q=!%a!#8T!	LLMAAm,
KK '"3"34
LL*GT:
LL\H& %%79ML
KKE\8-	l	 Qx=|]X]]_]$gkk2gkk:|DxOP)7;;>BAEEJffhRTUTYTY[^_ <ohoo>OPQ LL1<@IIl
LL0,? %  Q Qs2   :BK$AK$&K$	K K$K  K$$K-) F)NNF)__doc__r   r   r   r   r   rB   r4   r:   	getLogger__name__r?   r(   r   rP   r	       r   <module>rV      sJ   	 
 
      			8	$BH 	;?@rU   