
    -Ph                      `   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d dlZd dl	m
Z
 d dlZd dlZd dlmc mZ d dlmZ e j                            e j                            e                    Ze j                            ed          Ze j                            ed          Z ee          5 Zd  eed          D             Z ddd           n# 1 swxY w Y   da!d Z" G d	 d
ej#                  Z$ G d de$          Z% G d de%          Z&e'dk    r ej(                     dS dS )    N)	ccompiler)Cygdbcodefilecfuncs.cc                 >    i | ]\  }}|                                 |S  )strip).0ilines      c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/Debugger/Tests/TestLibCython.py
<dictcomp>r      s&    GGGGAt

aGGG       c            
         t           t           S da 	 t          j        g dt          j                  } |                                 \  }}d}t          j        ||                    dd                    }n# t          $ r d }Y nw xY w|r:t          t          t          |                                                    }|ddgk    rd	a t          j        d
          5 }|                    d           |                                 t          j        ddd|j        gt          j                  } |                                 \  }}	 t          t          t          |                    dd                                                              }|ddgk     rda n# t&          $ r da Y nw xY wd d d            n# 1 swxY w Y   t           st)          j        d           t           S )NF)gdbz-nxz	--version)stdoutzGNU gdb [^\d]*(\d+)\.(\d+)asciiignore      Tzw+)modez8python import sys; print("%s %s" % sys.version_info[:2])r   -batch-xz6Skipping gdb tests, need gdb >= 7.2 with Python >= 2.7)have_gdb
subprocessPopenPIPEcommunicaterematchdecodeOSErrorlistmapintgroupstempfileNamedTemporaryFilewriteflushnamesplit
ValueErrorwarningswarn)pr   _regexgdb_versiongdb_version_numberpython_version_scriptinternal_python_versions           r   test_gdbr8      s<   H	H888QQQ
 MMOO	-hufmmGX&F&FGG      %!#c;+=+=+?+?"@"@AA!Q''H,$777 %;P%++NP P P%++---$eXt=R=W%X,6O= = =MMOO	%.23sFMM'S[<\<\<b<b<d<d3e3e.f.f+.!Q77#(! % % %$HHH%% % % % % % % % % % % % % % %  PNOOOOsI   "A7 7BBA*F;
AFF;F,)F;+F,,F;;F?F?c                       e Zd Zd Zd ZdS )DebuggerTestCasec           	         t                      sdS t          j                    | _        t          j                            | j        d          | _        t          j                            | j        dd          | _        t          j                            | j        d          | _	        t	          j
                    | _        	 t	          j        | j                   t          j        t          | j                   t          j        t           | j	        dz              t          j        t                               dd          | j	        dz              t%          j                    }|                    dgd	d
g           t+          | j        d| j                  }t-          j                    }t1          j        d| j        dt1          j        t                    d|}t7          t          j        d          }t:          j        }|t:          _        |                                 	  |j         d| j        ddd	| j        dd| |!                    |d         |d         |d         dddgi           |"                                 |t:          _        |#                                 dS # |"                                 |t:          _        |#                                 w xY w#  t	          j        | j                    xY w)z
        Run gdb and have cygdb import the debug information from the code
        defined in TestParseTreeTransforms's setUp method
        Nzcodefile.pyxcython_debugcython_debug_info_codefilecfuncsz.cz.hr   Tz-fPIC)debugextra_postargsr   )test_directorymodulemodule_pathF)workdircleanup_workdirtagsw)	gdb_debug
output_dir)	targetdirincdirannotateextra_compile_optionsrA   rB   extra_objectszcfuncs.o)rA   rB   rD   rK   extra_extension_argsr   )$r8   r(   mkdtemptempdirospathjoindestfile
debug_destcfuncs_destfilegetcwdcwdchdirshutilcopyr   cfuncs_filereplacer   new_compilercompiledict	build_extOptimizationruntestsCythonCompileTestCase
parse_tagsopendevnullsysstderrdisable_optimization
run_cythonrun_distutilsrestore_stateclose)selfcompileroptsoptimization_disablercython_compile_testcase
new_stderrrj   s          r   setUpzDebuggerTestCase.setUpG   s   
 zz 	F'))T\>BB',,t|&4&BD D  "w||DL(CC9;;H	HT\"""K$-000KT%9D%@AAAK++D$77,t35 5 5 !-//Hj\wiPPP#|! M  D %.$:$<$<!&.&D ' %(22	' '
 ' '# bj#..JZF#CJ!66888#2'2 	"l"$(%)\+ +		 	 	 	 	 (55#'(8#9> !12*9:,)G 6    &33555#
  """"" &33555#
  """"	HTXs&   E#K" %AJ) 34K" )6KK" "K>c                     t                      sd S t          j        | j                   t	          j        | j                   d S N)r8   rR   rZ   rY   r[   rmtreerQ   )rp   s    r   tearDownzDebuggerTestCase.tearDown   s=    zz 	F
dl#####r   N)__name__
__module____qualname__rv   rz   r   r   r   r:   r:   E   s6        X X Xt$ $ $ $ $r   r:   c                   (     e Zd Z fdZ fdZ xZS )GdbDebuggerTestCasec           	         t                      sd S t                                                       t          j        d          }t          j        dt
          j        d d         d          }t          j        | j	        |          | _
        t          | j
        d          5 }|                    |           d d d            n# 1 swxY w Y   ddd| j
        d	d
t
          j        ddg	}g }t          j                            d          }|r|                    |           |                    t          j                            t          j                            t          j                            t*          j                                                 t/          t          j        t          j                            |                    }t5          j        |t4          j        t4          j        |          | _        d S )Na              python

            import os
            import sys
            import traceback

            def excepthook(type, value, tb):
                traceback.print_exception(type, value, tb)
                sys.stderr.flush()
                sys.stdout.flush()
                os._exit(1)

            sys.excepthook = excepthook

            # Have tracebacks end up on sys.stderr (gdb replaces sys.stderr
            # with an object that calls gdb.write())
            sys.stderr = sys.__stderr__

            end
            z            python

            from Cython.Debugger.Tests import test_libcython_in_gdb
            test_libcython_in_gdb.main(version=r   z)

            end
            ar   r   r   z-nz--argsz-czimport codefile
PYTHONPATH)r   )r   rj   env)r8   superrv   textwrapdedentri   version_infocygdbmake_command_filerQ   gdb_command_filerg   r*   
executablerR   environgetappendrS   dirnameabspathCython__file__ra   pathseprT   r   r   r   r1   )	rp   prefix_codecodefargspathsrS   r   	__class__s	           r   rv   zGdbDebuggerTestCase.setUp   s   zz 	Fo '  ,  #BQB''' * + + !& 78C!E !E $'-- 	GGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 xt'<dH&79 z~~l++ 	LLRW__RW__GOOFO,,&. &. / / 	0 	0 	02:"*//%*@*@AAA!??	  s   $CC
C
c                    t                      sd S 	 t                                                       | j        re| j        j                                         n#  Y nxY w| j        j                                         n#  Y nxY w| j                                         t          j	        | j
                   d S # t          j	        | j
                   w xY wrx   )r8   r   rz   r1   r   ro   rj   waitrR   remover   )rp   r   s    r   rz   zGdbDebuggerTestCase.tearDown   s    zz 	F		-GGv V]((****V]((****Id+,,,,,BId+,,,,s:   'B: A B: AB:  A? >B: ?BB: :C)r{   r|   r}   rv   rz   __classcell__)r   s   @r   r   r      sR        : : : : :x- - - - - - - - -r   r   c                       e Zd Zd ZdS )TestAllc                    t                      sd S | j                                        \  }}|                    d          }|                    d          }| j        j        }|dk    r@t
          j                            |           t
          j                            |           d S |dk    rGd}|d|}|d|}|d|}d|d||d||}t
          j                            |           d S d S )	NzUTF-8r   r   z******************************z   v INSIDE GDB v   z   v STDERR v   z   ^ INSIDE GDB ^   
)r8   r1   r   r"   
returncoderi   rj   r*   )	rp   outerrexit_statusborderstartrj   enderrmsgs	            r   test_allzTestAll.test_all   s   zz 	F6%%''Sjj!!jj!!f'!JS!!!JS!!!!!AF396666BE/5vvvv>F396666BCC+055##vvvssCCHFJV$$$$$ r   N)r{   r|   r}   r   r   r   r   r   r      s#        % % % % %r   r   __main__))rR   r    ri   r[   r/   r   unittestr(   r   	distutilsr   rd   Cython.Distutils.extensionr   Cython.Distutils.old_build_ext	Distutilsold_build_extrb   Cython.Debuggerr   r   rS   r   r   r   rootrT   r   r]   rg   r   	enumeratesource_to_linenor   r8   TestCaser:   r   r   r{   mainr   r   r   <module>r      sZ   				 				 



                  ! ! ! ! 2 2 2 2 2 2 2 2 2 * * * * * *	wrwx00117<<j))gll4,,	T(^^ HqGGyyAGGGH H H H H H H H H H H H H H H & & &R`$ `$ `$ `$ `$x( `$ `$ `$FK- K- K- K- K-* K- K- K-\% % % % %! % % %8 zHMOOOOO s   5CCC