
    xKg                        d 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mZ ddl	m
Z
 	  ed       dZ e
       Zej                  j                  d	      Zd
Z ej$                  ee      ZdZ ej$                  ee      Z	 ddlZdZdZ ej$                  ee      Z G d de      Zy# e$ r dZdZY ]w xY w# e$ r dZY 9w xY w)z'Helpers for running gdb related testing    N)config)_confirm_gdb)collect_gdbinfoF)need_ptrace_attachT3z;functioning gdb with correct ptrace permissions is requiredz gdb with python 3 support neededzpexpect module needed for testc                       e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
dd
Zd Zd Zd Zd Zd ZddZddZddZddZddZd Zd Zy)GdbMIDriverzs
    Driver class for the GDB machine interface:
    https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html
    Nc                     t         sd}t        |      t        sd}t        |      t        j                  | _        t        j                  | _        || _	        || _
        || _        || _        | j                          y )Nz[This driver requires the pexpect module. This can be obtained via:

$ conda install pexpectzWThis driver requires a gdb binary. This can be obtained via the system package manager.)_HAVE_PEXPECTRuntimeError	_HAVE_GDBr   
GDB_BINARY_gdb_binarysys
executable_python_debug
_file_name_timeout
_init_cmds_drive)self	file_namedebugtimeout	init_cmdsmsgs         [/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/tests/gdb_support.py__init__zGdbMIDriver.__init__+   sj    >Cs##>Cs##!,,~~##    c                    t         j                  j                  | j                        sJ | j                  ddg}| j
                  |t        | j
                        z  }|d| j                  | j                  gz  }t        j                  dj                  |            | _        | j                  r*t        j                  j                  | j                  _        yy)z0This function sets up the caputured gdb instancez--interpretermiNz--args )ospathisfiler   r   r   listr   pexpectspawnjoin	_capturedr   r   stdoutbufferlogfiler   cmds     r   r   zGdbMIDriver._drive<   s    ww~~doo...$7??&4((C$,,88 sxx}5;;%(ZZ%6%6DNN" r    c                 &    d| j                         v S )z_Returns True if the underlying gdb implementation has python support
           False otherwisepython)list_featuresr   s    r   supports_pythonzGdbMIDriver.supports_pythonG   s     4--///r    c                     | j                         syd}| j                  d|       d| j                  j                  j	                         v S )zReturns True if the underlying gdb implementation has NumPy support
           (and by extension Python support) False otherwiseFzGpython from __future__ import print_function;import numpy; print(numpy)consolezmodule 'numpy' from)r5   interpreter_execr+   beforedecoder/   s     r   supports_numpyzGdbMIDriver.supports_numpyL   sH     ##%,i-&$..*?*?*F*F*HHHr    c                     	 | j                   j                  || j                         y # t        j                  j
                  $ r}d| d}t        |      |d }~ww xY w)N)r   zExpected value did not arrive: .)r+   expectr   r(   
exceptionsTIMEOUT
ValueError)r   r>   er   s       r   _captured_expectzGdbMIDriver._captured_expectW   sX    	)NN!!&$--!@!!)) 	)3F81=CS/q(	)s   '* AAAc                 v    | j                   j                  }|j                  d      }||v sJ d| d| d       y)z=Asserts that the current output string contains the expected.utf-8decoded=

expected=)N)r+   afterr:   )r   expectedoutputdecodeds       r   assert_outputzGdbMIDriver.assert_output^   sA    %%--(7"Nhwi{8*A$NN"r    c                     | j                   j                  }|j                  d      }|j                         d   }t	        j
                  ||      }|sJ d| d| d       y)zKAsserts that the current output string contains the expected
        regex.rE   r   rF   rG   rH   N)r+   rI   r:   
splitlinesrematch)r   rJ   rK   rL   done_strfounds         r   assert_regex_outputzGdbMIDriver.assert_regex_outputd   s`     %%--(%%'*8,@	XJa@@ur    c                 \    | j                   j                  |       | j                  |       y )N)r+   sendlinerC   )r   commandr>   s      r   _run_commandzGdbMIDriver._run_commandm   s"    (f%r    c                 *    | j                  dd       y)zgdb command ~= 'run'z	-exec-run\^running.*\r\nr>   NrX   r4   s    r   runzGdbMIDriver.runq   s    +.@Ar    c                 *    | j                  dd       y)zgdb command ~= 'continue'z-exec-continuerZ   r[   Nr\   r4   s    r   contzGdbMIDriver.contu   s    *3EFr    c                 ^    | j                  dd       | j                  j                          y)zgdb command ~= 'quit'z	-gdb-exitr[   N)rX   r+   	terminater4   s    r   quitzGdbMIDriver.quity   s%    +l;  "r    c                 *    | j                  dd       y)zgdb command ~= 'next'z
-exec-next\*stopped,.*\r\nr[   Nr\   r4   s    r   nextzGdbMIDriver.next~       ,/BCr    c                 *    | j                  dd       y)zgdb command ~= 'step'z
-exec-steprd   r[   Nr\   r4   s    r   stepzGdbMIDriver.step   rf   r    c                     ||t        d      d}|	|d| dz  }|(t        |t              sJ |d| j                   d| dz  }|t        |t              sJ |d| dz  }| j                  |d	
       y)zgdb command ~= 'break'Nz%Can only supply one of line or symbolz-break-insert z-c "z" z-f :r#   z\^doner[   )rA   
isinstanceintr   strrX   )r   linesymbol	conditionbps        r   set_breakpointzGdbMIDriver.set_breakpoint   s     2DEE D2&&BdC(((C($q11Bfc***Cxq/!B"Y/r    c                     | j                  d       | j                  d       |'t        |t              sJ | j                  d| d       |(t        |t              sJ | j                  d| d       yy)z%Checks that a breakpoint has been hitrd   z!*stopped,reason="breakpoint-hit",Nzbkptno=""zline=")rC   rM   rk   rl   )r   numberrn   s      r   check_hit_breakpointz GdbMIDriver.check_hit_breakpoint   s    12>?fc***&34dC(((vQ/0 r    c                     |||fD ]  }t        |t              r|dv rJ  d| d| d| }| j                  |d       y)zgdb command ~= 'info args'r         z-stack-list-arguments r#   \^done,.*\r\nr[   Nrk   rl   rX   )r   print_values	low_frame
high_framexr0   s         r   stack_list_argumentsz GdbMIDriver.stack_list_arguments   sU    	:6Aa%!y.88 7&|nAi[*N#&67r    c                 `    t        |t              r|dv sJ d| }| j                  |d       y)zgdb command ~= 'info locals'rx   z-stack-list-variables r{   r[   Nr|   )r   r}   r0   s      r   stack_list_variablesz GdbMIDriver.stack_list_variables   s9    ,,1JJJ&|n5#&67r    c                 p    |t        d      |t        d      d| d| d}| j                  |d       y)	z!gdb command ~= 'interpreter-exec'Nzinterpreter cannot be Nonezcommand cannot be Nonez-interpreter-exec z "rt   z\^(done|error).*\r\nr[   )rA   rX   )r   interpreterrW   r0   s       r   r8   zGdbMIDriver.interpreter_exec   sM    9::?566";-r'!<#&=>r    c                 .    d}| j                  |d       y )Nz-list-featuresr{   r[   r\   r/   s     r   _list_features_rawzGdbMIDriver._list_features_raw   s    #&67r    c                 @   | j                          | j                  j                  }|j                  d      }t	        j
                  d|      }|J d       |j                         }t        |      dk(  sJ d       |d   j                  dd      j                  d	      S )
zXNo equivalent gdb command? Returns a list of supported gdb
           features.
        rE   z.*features=\[(.*)\].*z"No match found for features stringry   z$Invalid number of match groups foundr   rt    ,)
r   r+   rI   r:   rP   rQ   groupslenreplacesplit)r   rK   rL   mgs        r   r3   zGdbMIDriver.list_features   s     	!%%--(HH.8}BBB}HHJ1v{BBB{t||C$**3//r    )Fx   N)r   )NNN)NN)ry   r   r   )ry   )__name__
__module____qualname____doc__r   r   r5   r;   rC   rM   rT   rX   r]   r_   rb   re   rh   rr   rv   r   r   r8   r   r3    r    r   r	   r	   &   sr    "	70
	I)OA&BG#
DD0	188?80r    r	   )r   r$   rP   r   unittest
numba.corer   numba.misc.gdb_hookr   numba.misc.numba_gdbinfor   r   	_gdb_infopy_ver
startswith_GDB_HAS_PY3	Exception_msg
skipUnless	needs_gdbneeds_gdb_py3r(   r   ImportErrorskip_unless_pexpectobjectr	   r   r    r   <module>r      s    - 	 	 
   , 4E*I!I##..s3L
 EH	40	)###L$7M
 ()h))-> _0& _0-  IL  Ms#   -B% >B4 %	B10B14B>=B>