
    sh                        S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
   \" SS9  Sr\
" 5       r\R                  R                  S	5      rS
r\R$                  " \\5      rSr\R$                  " \\5      r SSKrSrSr\R$                  " \\5      r " S S\5      rg! \ a    SrSr N^f = f! \ a    Sr N;f = f)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                       \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rSS jrS rS rS rS rS rSS jrSS jrSS jrSS jrSS jrS rS rSrg)GdbMIDriver&   zg
Driver class for the GDB machine interface:
https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html
Nc                    [         (       d  Sn[        U5      e[        (       d  Sn[        U5      e[        R                  U l        [        R                  U l        X l	        Xl
        X0l        X@l        U R                  5         g )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         k/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/tests/gdb_support.py__init__GdbMIDriver.__init__+   sf    }>Cs##y>Cs##!,,~~##    c                    [         R                  R                  U R                  5      (       d   eU R                  SS/nU R
                  b  U[        U R
                  5      -  nUSU R                  U R                  /-  n[        R                  " SR                  U5      5      U l        U R                  (       a*  [        R                  R                  U R                  l        gg)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   GdbMIDriver._drive<   s    ww~~doo....$7??&4((C$,,88 sxx}5;;%(ZZ%6%6DNN" r"   c                 (    SU R                  5       ;   $ )zTReturns True if the underlying gdb implementation has python support
False otherwisepython)list_featuresr   s    r   supports_pythonGdbMIDriver.supports_pythonG   s     4--///r"   c                     U R                  5       (       d  gSnU R                  SU5        SU R                  R                  R	                  5       ;   $ )zuReturns 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)r8   interpreter_execr-   beforedecoder1   s     r   supports_numpyGdbMIDriver.supports_numpyL   sK     ##%%,i-&$..*?*?*F*F*HHHr"   c                      U R                   R                  XR                  S9  g ! [        R                  R
                   a  nSU S3n[        U5      UeS nAff = f)N)r   zExpected value did not arrive: .)r-   expectr   r*   
exceptionsTIMEOUT
ValueError)r   rC   er   s       r   _captured_expectGdbMIDriver._captured_expectW   sV    	)NN!!&--!@!!)) 	)3F81=CS/q(	)s   #& AAAc                 x    U R                   R                  nUR                  S5      nX;   d   SU SU S35       eg)z=Asserts that the current output string contains the expected.utf-8decoded=

expected=)N)r-   afterr>   )r   expectedoutputdecodeds       r   assert_outputGdbMIDriver.assert_output^   s?    %%--("Nhwi{8*A$NN"r"   c                     U R                   R                  nUR                  S5      nUR                  5       S   n[        R
                  " X5      nU(       d   SU SU S35       eg)zCAsserts that the current output string contains the expected
regex.rK   r   rL   rM   rN   N)r-   rO   r>   
splitlinesrematch)r   rP   rQ   rR   done_strfounds         r   assert_regex_outputGdbMIDriver.assert_regex_outputd   s^     %%--(%%'*,@	XJa@@ur"   c                 \    U R                   R                  U5        U R                  U5        g )N)r-   sendlinerH   )r   commandrC   s      r   _run_commandGdbMIDriver._run_commandm   s"    (f%r"   c                 $    U R                  SSS9  g)zgdb command ~= 'run'z	-exec-run\^running.*\r\nrC   Nr`   r7   s    r   runGdbMIDriver.runq   s    +.@Ar"   c                 $    U R                  SSS9  g)zgdb command ~= 'continue'z-exec-continuerc   rd   Nre   r7   s    r   contGdbMIDriver.contu   s    *3EFr"   c                 X    U R                  SSS9  U R                  R                  5         g)zgdb command ~= 'quit'z	-gdb-exitrd   N)r`   r-   	terminater7   s    r   quitGdbMIDriver.quity   s%    +l;  "r"   c                 $    U R                  SSS9  g)zgdb command ~= 'next'z
-exec-next\*stopped,.*\r\nrd   Nre   r7   s    r   nextGdbMIDriver.next~       ,/BCr"   c                 $    U R                  SSS9  g)zgdb command ~= 'step'z
-exec-steprp   rd   Nre   r7   s    r   stepGdbMIDriver.step   rs   r"   c                    Ub  Ub  [        S5      eSnUb	  USU S3-  nUb-  [        U[        5      (       d   eUSU R                   SU S3-  nUb   [        U[        5      (       d   eUSU S3-  nU R                  US	S
9  g)zgdb command ~= 'break'Nz%Can only supply one of line or symbolz-break-insert z-c "z" z-f :r%   z\^donerd   )rF   
isinstanceintr   strr`   )r   linesymbol	conditionbps        r   set_breakpointGdbMIDriver.set_breakpoint   s     2DEE D2&&BdC((((C($q11Bfc****Cxq/!B"Y/r"   c                    U R                  S5        U R                  S5        Ub,  [        U[        5      (       d   eU R                  SU S35        Ub-  [        U[        5      (       d   eU R                  SU S35        gg)z%Checks that a breakpoint has been hitrp   z!*stopped,reason="breakpoint-hit",Nzbkptno=""zline=")rH   rS   ry   rz   )r   numberr|   s      r   check_hit_breakpoint GdbMIDriver.check_hit_breakpoint   s    12>?fc****&34dC((((vQ/0 r"   c                     XU4 H   n[        U[        5      (       a  US;   a  M    e   SU SU SU 3nU R                  USS9  g)zgdb command ~= 'info args'r         z-stack-list-arguments r%   \^done,.*\r\nrd   Nry   rz   r`   )r   print_values	low_frame
high_framexr2   s         r   stack_list_arguments GdbMIDriver.stack_list_arguments   sV    :6Aa%%!y.88 7&|nAi[*N#&67r"   c                 h    [        U[        5      (       a  US;   d   eSU 3nU R                  USS9  g)zgdb command ~= 'info locals'r   z-stack-list-variables r   rd   Nr   )r   r   r2   s      r   stack_list_variables GdbMIDriver.stack_list_variables   s<    ,,,1JJJ&|n5#&67r"   c                 n    Uc  [        S5      eUc  [        S5      eSU SU S3nU R                  USS9  g)	z!gdb command ~= 'interpreter-exec'Nzinterpreter cannot be Nonezcommand cannot be Nonez-interpreter-exec z "r   z\^(done|error).*\r\nrd   )rF   r`   )r   interpreterr_   r2   s       r   r<   GdbMIDriver.interpreter_exec   sM    9::?566";-r'!<#&=>r"   c                 (    SnU R                  USS9  g )Nz-list-featuresr   rd   re   r1   s     r   _list_features_rawGdbMIDriver._list_features_raw   s    #&67r"   c                 F   U R                  5         U R                  R                  nUR                  S5      n[        R
                  " SU5      nUc   S5       eUR                  5       n[        U5      S:X  d   S5       eUS   R                  SS5      R                  S	5      $ )
zENo equivalent gdb command? Returns a list of supported gdb
features.
rK   z.*features=\[(.*)\].*z"No match found for features stringr   z$Invalid number of match groups foundr   r    ,)
r   r-   rO   r>   rW   rX   groupslenreplacesplit)r   rQ   rR   mgs        r   r6   GdbMIDriver.list_features   s     	!%%--(HH.8}BBB}HHJ1v{BBB{t||C$**3//r"   )r-   r   r   r   r   r   r   )Fx   N)r   )NNN)NN)r   r   r   )r   )__name__
__module____qualname____firstlineno____doc__r    r   r8   r?   rH   rS   r[   r`   rf   ri   rm   rq   ru   r   r   r   r   r<   r   r6   __static_attributes__ r"   r   r	   r	   &   sr    "	70
	I)OA&BG#
DD0	188?80r"   r	   )r   r&   rW   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	40	)##L$7M
 ())-> _0& _0-  IL  Ms#   *B" ;B2 "
B/.B/2B=<B=