
    J/Ph                        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                            d	          Zn# e$ r dZdZY nw xY wd
Z ej        ee          ZdZ ej        ee          Z	 ddlZdZn# e$ r dZY nw xY wdZ ej        ee          Z G d de          ZdS )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dS )"GdbMIDriverzs
    Driver class for the GDB machine interface:
    https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html
    Fx   Nc                 
   t           sd}t          |          t          sd}t          |          t          j        | _        t          j        | _        || _	        || _
        || _        || _        |                                  d S )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         W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/gdb_support.py__init__zGdbMIDriver.__init__+   s}     	$>Cs### 	$>Cs###!,~##    c                 f   t           j                            | j                  sJ | j        ddg}| j        |t          | j                  z  }|d| j        | j        gz  }t          j	        d
                    |                    | _        | j        rt          j        j        | j        _        dS dS )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    w~~do.....$7?&4(((C$,88 sxx}}55; 	7%(Z%6DN"""	7 	7r!   c                 .    d|                                  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                     |                                  sdS d}|                     d|           d| 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)r6   interpreter_execr,   beforedecoder0   s     r   supports_numpyzGdbMIDriver.supports_numpyL   sV     ##%% 	5,i---&$.*?*F*F*H*HHHr!   c                     	 | j                             || j                   d S # 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   sm    	)N!!&$-!@@@@@!) 	) 	) 	)=F===CS//q(	)s   !% AAAc                 r    | j         j        }|                    d          }||v sJ d| d| d            dS )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^   sP    %--((7"""$Nw$N$N8$N$N$N"""""r!   c                     | j         j        }|                    d          }|                                d         }t	          j        ||          }|sJ d| d| d            dS )zKAsserts that the current output string contains the expected
        regex.rF   r   rG   rH   rI   N)r,   rJ   r;   
splitlinesrematch)r   rK   rL   rM   done_strfounds         r   assert_regex_outputzGdbMIDriver.assert_regex_outputd   st     %--((%%''*8,,@@@@@X@@@@@@@@r!    c                 d    | j                             |           |                     |           d S )N)r,   sendlinerD   )r   commandr?   s      r   _run_commandzGdbMIDriver._run_commandm   s2    (((f%%%%%r!   c                 4    |                      dd           dS )zgdb command ~= 'run'z	-exec-run\^running.*\r\nr?   NrZ   r5   s    r   runzGdbMIDriver.runq   s"    +.@AAAAAr!   c                 4    |                      dd           dS )zgdb command ~= 'continue'z-exec-continuer\   r]   Nr^   r5   s    r   contzGdbMIDriver.contu   s#    *3EFFFFFr!   c                 f    |                      dd           | j                                         dS )zgdb command ~= 'quit'z	-gdb-exitr]   N)rZ   r,   	terminater5   s    r   quitzGdbMIDriver.quity   s5    +l;;;  """""r!   c                 4    |                      dd           dS )zgdb command ~= 'next'z
-exec-next\*stopped,.*\r\nr]   Nr^   r5   s    r   nextzGdbMIDriver.next~   "    ,/BCCCCCr!   c                 4    |                      dd           dS )zgdb command ~= 'step'z
-exec-steprf   r]   Nr^   r5   s    r   stepzGdbMIDriver.step   rh   r!   c                    ||t          d          d}|	|d| dz  }|(t          |t                    sJ |d| j         d| dz  }| t          |t                    sJ |d| dz  }|                     |d	
           dS )zgdb command ~= 'break'Nz%Can only supply one of line or symbolz-break-insert z-c "z" z-f :r$   z\^doner]   )rB   
isinstanceintr   strrZ   )r   linesymbol	conditionbps        r   set_breakpointzGdbMIDriver.set_breakpoint   s     2DEEE &&&&&BdC(((((111$1111Bfc*****////!B"Y/////r!   c                 &   |                      d           |                     d           |0t          |t                    sJ |                     d| d           |2t          |t                    sJ |                     d| d           dS dS )z%Checks that a breakpoint has been hitrf   z!*stopped,reason="breakpoint-hit",Nzbkptno=""zline=")rD   rN   rm   rn   )r   numberrp   s      r   check_hit_breakpointz GdbMIDriver.check_hit_breakpoint   s    1222>???fc*****3&333444dC(((((////00000 r!      r   c                     |||fD ]}t          |t                    r|dv sJ d| d| d| }|                     |d           dS )zgdb command ~= 'info args'r   ry      z-stack-list-arguments r$   \^done,.*\r\nr]   Nrm   rn   rZ   )r   print_values	low_frame
high_framexr1   s         r   stack_list_argumentsz GdbMIDriver.stack_list_arguments   ss    	:6 	9 	9Aa%%8!y.....N|NNiNN*NN#&677777r!   c                 t    t          |t                    r|dv sJ d| }|                     |d           dS )zgdb command ~= 'info locals'r{   z-stack-list-variables r}   r]   Nr~   )r   r   r1   s      r   stack_list_variablesz GdbMIDriver.stack_list_variables   sO    ,,,J1J1J1J1J5|55#&677777r!   c                     |t          d          |t          d          d| d| d}|                     |d           dS )	z!gdb command ~= 'interpreter-exec'Nzinterpreter cannot be Nonezcommand cannot be Nonez-interpreter-exec z "rv   z\^(done|error).*\r\nr]   )rB   rZ   )r   interpreterrY   r1   s       r   r9   zGdbMIDriver.interpreter_exec   sc    9:::?5666<;<<'<<<#&=>>>>>r!   c                 8    d}|                      |d           d S )Nz-list-featuresr}   r]   r^   r0   s     r   _list_features_rawzGdbMIDriver._list_features_raw   s'    #&677777r!   c                 n   |                                   | j        j        }|                    d          }t	          j        d|          }|
J d            |                                }t          |          dk    s
J d            |d                             dd	          	                    d
          S )zXNo equivalent gdb command? Returns a list of supported gdb
           features.
        rF   z.*features=\[(.*)\].*Nz"No match found for features stringry   z$Invalid number of match groups foundr   rv   rV   ,)
r   r,   rJ   r;   rQ   rR   groupslenreplacesplit)r   rL   rM   mgs        r   r4   zGdbMIDriver.list_features   s     	!!!%--((H.88}}B}}}HHJJ1vv{{{B{{{t||C$$**3///r!   )Fr
   N)rV   )NNN)NN)ry   r   r   )ry   )__name__
__module____qualname____doc__r    r   r6   r<   rD   rN   rU   rZ   r_   ra   rd   rg   rj   rt   rx   r   r   r9   r   r4    r!   r   r	   r	   &   s           "	7 	7 	70 0 0
	I 	I 	I) ) )O O OA A A& & & &B B BG G G# # #
D D DD D D0 0 0 0	1 	1 	1 	18 8 8 88 8 8 8? ? ? ?8 8 80 0 0 0 0r!   r	   )r   r%   rQ   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 4 4 4 4 4LE****I!!I#..s33LL   ILLL EH	400	)##L$77NNNMM   MMM ()h)->> _0 _0 _0 _0 _0& _0 _0 _0 _0 _0s#   2A 	A%$A%B B B 