o
    i                     @   s   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
 zedd dZe
 Zejd	ZW n eyC   dZdZY nw d
ZeeeZdZeeeZzddlZdZW n eyg   dZY nw dZeeeZG dd deZdS )z'Helpers for running gdb related testing    N)config)_confirm_gdb)collect_gdbinfoF)Zneed_ptrace_attachT3z;functioning gdb with correct ptrace permissions is requiredz gdb with python 3 support neededzpexpect module needed for testc                   @   s   e Zd ZdZd0ddZdd Zd	d
 Zdd Zdd Zdd Z	dd Z
d1ddZdd Zdd Zdd Zdd Zdd Zd2d d!Zd3d"d#Zd4d&d'Zd5d(d)Zd3d*d+Zd,d- Zd.d/ ZdS )6GdbMIDriverzs
    Driver class for the GDB machine interface:
    https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html
    Fx   Nc                 C   sT   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   Z
GDB_BINARY_gdb_binarysys
executable_python_debug
_file_name_timeout
_init_cmds_drive)self	file_namedebugtimeoutZ	init_cmdsmsg r   f/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/gdb_support.py__init__+   s   zGdbMIDriver.__init__c                 C   st   t j| js	J | jddg}| jdur|t| j7 }|d| j| jg7 }t	d
|| _| jr8tjj| j_dS dS )z0This function sets up the caputured gdb instancez--interpretermiNz--args )ospathisfiler   r   r   listr   pexpectZspawnjoin	_capturedr   r   stdoutbufferZlogfiler   cmdr   r   r   r   <   s   
zGdbMIDriver._drivec                 C   s   d|   v S )z_Returns True if the underlying gdb implementation has python support
           False otherwisepython)list_featuresr   r   r   r   supports_pythonG   s   zGdbMIDriver.supports_pythonc                 C   s,   |   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)r,   interpreter_execr$   beforedecoder'   r   r   r   supports_numpyL   s
   zGdbMIDriver.supports_numpyc              
   C   sL   z| j j|| jd W d S  tjjy% } zd| d}t||d }~ww )N)r   zExpected value did not arrive: .)r$   expectr   r"   
exceptionsTIMEOUT
ValueError)r   r3   er   r   r   r   _captured_expectW   s   
zGdbMIDriver._captured_expectc                 C   s4   | 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$   afterr0   )r   expectedoutputdecodedr   r   r   assert_output^   s   
"zGdbMIDriver.assert_outputc                 C   sH   | j j}|d}| d }t||}|s"J d| d| ddS )zKAsserts that the current output string contains the expected
        regex.r9   r   r:   r;   r<   N)r$   r=   r0   
splitlinesrematch)r   r>   r?   r@   Zdone_strfoundr   r   r   assert_regex_outputd   s
   
zGdbMIDriver.assert_regex_output c                 C   s   | j | | | d S )N)r$   Zsendliner8   )r   commandr3   r   r   r   _run_commandm   s   zGdbMIDriver._run_commandc                 C      | j ddd dS )zgdb command ~= 'run'z	-exec-run\^running.*\r\nr3   NrI   r+   r   r   r   runq      zGdbMIDriver.runc                 C   rJ   )zgdb command ~= 'continue'z-exec-continuerK   rL   NrM   r+   r   r   r   contu   rO   zGdbMIDriver.contc                 C   s   | j ddd | j  dS )zgdb command ~= 'quit'z	-gdb-exitrL   N)rI   r$   	terminater+   r   r   r   quity   s   zGdbMIDriver.quitc                 C   rJ   )zgdb command ~= 'next'z
-exec-next\*stopped,.*\r\nrL   NrM   r+   r   r   r   next~   rO   zGdbMIDriver.nextc                 C   rJ   )zgdb command ~= 'step'z
-exec-steprS   rL   NrM   r+   r   r   r   step   rO   zGdbMIDriver.stepc                 C   s   |dur|durt dd}|dur|d| d7 }|dur1t|ts%J |d| j d| d7 }|durDt|ts<J |d| d7 }| j|d	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\^donerL   )r6   
isinstanceintr   strrI   )r   linesymbol	conditionbpr   r   r   set_breakpoint   s   zGdbMIDriver.set_breakpointc                 C   sl   |  d | d |durt|tsJ | d| d |dur4t|ts)J | d| d dS dS )z%Checks that a breakpoint has been hitrS   z!*stopped,reason="breakpoint-hit",Nzbkptno=""zline=")r8   rA   rW   rX   )r   numberrZ   r   r   r   check_hit_breakpoint   s   

z GdbMIDriver.check_hit_breakpoint   r   c                 C   sN   |||fD ]}t |tr|dv sJ qd| d| d| }| j|dd dS )zgdb command ~= 'info args'r   rb      z-stack-list-arguments r   \^done,.*\r\nrL   NrW   rX   rI   )r   print_valuesZ	low_frameZ
high_framexr(   r   r   r   stack_list_arguments   s   z GdbMIDriver.stack_list_argumentsc                 C   s2   t |tr	|dv sJ d| }| j|dd dS )zgdb command ~= 'info locals'rc   z-stack-list-variables re   rL   Nrf   )r   rg   r(   r   r   r   stack_list_variables   s   
z GdbMIDriver.stack_list_variablesc                 C   sD   |du rt d|du rt dd| d| d}| j|dd dS )	z!gdb command ~= 'interpreter-exec'Nzinterpreter cannot be Nonezcommand cannot be Nonez-interpreter-exec z "r_   z\^(done|error).*\r\nrL   )r6   rI   )r   interpreterrH   r(   r   r   r   r.      s   zGdbMIDriver.interpreter_execc                 C   s   d}| j |dd d S )Nz-list-featuresre   rL   rM   r'   r   r   r   _list_features_raw   s   zGdbMIDriver._list_features_rawc                 C   sh   |    | jj}|d}td|}|dusJ d| }t|dks)J d|d dd		d
S )zXNo equivalent gdb command? Returns a list of supported gdb
           features.
        r9   z.*features=\[(.*)\].*Nz"No match found for features stringrb   z$Invalid number of match groups foundr   r_   rG   ,)
rl   r$   r=   r0   rC   rD   groupslenreplacesplit)r   r?   r@   mgr   r   r   r*      s   
zGdbMIDriver.list_features)Fr   N)rG   )NNN)NN)rb   r   r   )rb   )__name__
__module____qualname____doc__r   r   r,   r1   r8   rA   rF   rI   rN   rP   rR   rT   rU   r^   ra   ri   rj   r.   rl   r*   r   r   r   r   r   &   s,    

	




	r   )rw   r   rC   r   ZunittestZ
numba.corer   Znumba.misc.gdb_hookr   Znumba.misc.numba_gdbinfor   r
   Z	_gdb_infoZpy_ver
startswithZ_GDB_HAS_PY3	ExceptionZ_msgZ
skipUnlessZ	needs_gdbZneeds_gdb_py3r"   r   ImportErrorZskip_unless_pexpectobjectr   r   r   r   r   <module>   s<    
