
    Ae                      P   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*                  j-                  e j*                  j/                  e            Ze j*                  j5                  ed      Ze j*                  j5                  ed      Z ee      5 Z ed  e e      D              Z!ddd       da"d Z# G d d	ejH                        Z% G d
 de%      Z& G d de&      Z'e(dk(  r ejR                          yy# 1 sw Y   QxY w)    N)	ccompiler)Cygdbcodefilecfuncs.cc              #   L   K   | ]  \  }}|j                         |d z   f  yw)   N)strip).0ilines      Clib/python3.12/site-packages/Cython/Debugger/Tests/TestLibCython.py	<genexpr>r      s#     NgaTZZ\1q51Ns   "$c            
      v   t         t         S da 	 t        j                  g dt        j                        } | j	                         \  }}d}t        j                  ||j                  dd            }|rt        t        t        |j                                     }|ddgk\  rd	a t        j                  d
      5 }|j                  d       |j!                          t        j                  ddd|j"                  gt        j                        } | j	                         \  }}	 t        t        t        |j                  dd      j%                                     }|ddgk  rda d d d        t         st)        j*                  d       t         S # t        $ r d }Y (w xY w# t&        $ r da Y Hw xY w# 1 sw Y   MxY w)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-x   z6Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6)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_gdbr7      s   H	H8Q
 MMO	-hhufmmGX&FG!#c;+=+=+?"@A!Q'H,,$7 %;P%++NP%++-$$eXt=R=W=W%X,6OO=MMO	%.23sFMM'S[<\<b<b<d3e.f+.!Q7#(% NOO=  0 " %$H%% %s=   'F :A(F/#A FFFF,)F/+F,,F//F8c                       e Zd Zd Zd Zy)DebuggerTestCasec           	      *   t               syt        j                         | _        t        j
                  j                  | j                  d      | _        t        j
                  j                  | j                  dd      | _        t        j
                  j                  | j                  d      | _	        t	        j                         | _        	 t	        j                  | j                         t        j                  t        | j                         t        j                  t         | j                  dz          t        j                  t         j#                  dd      | j                  dz          t%        j&                         }|j)                  dgd	d
g       t+        | j                  d      }t-        j.                         }t1        j2                  d| j                  dt1        j4                  t              d|}t7        t        j8                  d      }t:        j<                  }|t:        _        |j?                          	  |j@                  d| j                  ddd	| j                  dd|  |jB                  dd| j                  ddgid| |jE                          |t:        _        |jG                          y# |jE                          |t:        _        |jG                          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moduleF)workdircleanup_workdirtagsw)	gdb_debug
output_dir)	targetdirincdirannotateextra_compile_optionsextra_objectszcfuncs.o)rI   rB   extra_extension_args )$r7   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_stderrri   s          r   setUpzDebuggerTestCase.setUpH   ss   
 z'')T\\>B'',,t||&4&BD  "ww||DLL(C99;F	HHT\\"KK$--0KKT%9%9D%@AKK++D$7,,t35 !--/Hj\wiP#||!D
 %.$:$:$<!&.&D&D ' %((2	'
 '# bjj#.JZZF#CJ!668#2'22 	"ll"$(%)\\+		 	 6'55  LL*9:,)G 	 &335#
  " &335#
  "	HHTXXs&   E5K0 AK  +K0  -K--K0 0"Lc                     t               sy t        j                  | j                         t	        j
                  | j                         y N)r7   rQ   rY   rX   rZ   rmtreerP   )ro   s    r   tearDownzDebuggerTestCase.tearDown   s*    z
dll#    N)__name__
__module____qualname__ru   ry   rN   rz   r   r9   r9   F   s    Vp$rz   r9   c                   (     e Zd Z fdZ fdZ xZS )GdbDebuggerTestCasec           	          t               sy t        t        |           t	        j
                  d      }t	        j
                  dt        j                  d d d      }t        j                  | j                  |      | _        t        | j                  d      5 }|j                  |       d d d        ddd| j                  d	d
t        j                  ddg	}g }t        j                   j#                  d      }|r|j%                  |       |j%                  t        j&                  j)                  t        j&                  j)                  t        j&                  j+                  t,        j.                                           t1        t        j                   t        j2                  j5                  |            }t7        j8                  |t6        j:                  t6        j:                  |      | _        y # 1 sw Y   JxY w)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   ri   env)r7   superr   ru   textwrapdedentrh   version_infocygdbmake_command_filerP   gdb_command_filerf   r)   
executablerQ   environgetappendrR   dirnameabspathCython__file__r`   pathseprS   r   r   r   r0   )	ro   prefix_codecodefargspathsrR   r   	__class__s	           r   ru   zGdbDebuggerTestCase.setUp   sw   z!4.0oo ' ,  ##BQ' * + !& 7 78C!E $''- 	GGDM	 xt'<'<dH&79 zz~~l+LLRWW__RWW__GGOOFOO,&. / 	02::"**//%*@A!!????		 	s   G33G=c                    t               sy 	 t        t        |           | j                  rb| j                  j
                  j                          | j                  j                  j                          | j                  j                          t        j                  | j                         y #  Y bxY w#  Y ExY w# t        j                  | j                         w xY wrw   )r7   r   r   ry   r0   r   rn   ri   waitrQ   remover   )ro   r   s    r   ry   zGdbDebuggerTestCase.tearDown   s    z		-%t57vvVV]]((*VV]]((*IId++,  IId++,s4   B< $B. $B5 4B< .B20B< 5B97B< <!C)r{   r|   r}   ru   ry   __classcell__)r   s   @r   r   r      s    :x- -rz   r   c                       e Zd Zd Zy)TestAllc                    t               sy | j                  j                         \  }}|j                  d      }|j                  d      }| j                  j                  }|dk(  r?t
        j                  j                  |       t
        j                  j                  |       y |dk\  rFd}|d|}|d|}|d|}d|d||d||}t
        j                  j                  |       y y )	NzUTF-8r   r   z******************************z   v INSIDE GDB v   z   v STDERR v   z   ^ INSIDE GDB ^   
)r7   r0   r   r!   
returncoderh   ri   r)   )	ro   outerrexit_statusborderstartri   enderrmsgs	            r   test_allzTestAll.test_all   s    z66%%'Sjj!jj!ff''!JJS!JJS!AF4:FCE06?F4:FCC,13SIFJJV$ rz   N)r{   r|   r}   r   rN   rz   r   r   r      s    %rz   r   __main__)*rQ   r   rh   rZ   r.   r   unittestr'   r   	distutilsr   rc   Cython.Distutils.extensionr   Cython.Distutils.old_build_ext	Distutilsold_build_extra   Cython.Debuggerr   r   rR   r   r   r   rootrS   r   r\   rf   r   r`   	enumeratesource_to_linenor   r7   TestCaser9   r   r   r{   mainrN   rz   r   <module>r      s   	 	 
          ! 2 2 *	wwrwwx0177<<j)ggll4,	(^ OqN1NNO &R^$x(( ^$BK-* K-\%! %8 zHMMO sO Os   6DD%