
    <e                         d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZ d Z	 e
ed          Z ej        ed           G d dej                              Zed	k    r ej                     dS dS )
    N)	os_helperverbose)assert_python_okc                      g } t          d          D ]}|                     |           d} d}t          | |           d S )N   zthis isz
an example)rangeappendprint)xiys      (/usr/lib/python3.11/test/test_lltrace.pyexampler   	   sH    
A1XX  	AA	!QKKKKK    gettotalrefcountzlltrace requires Py_DEBUGc                   &    e Zd Zd Zd Zd Zd ZdS )TestLLTracec                    t          j        |                                          }t          t          j        dd          5 }|                     t          j        t          j                   |                    |           d d d            n# 1 swxY w Y   t          t          j                  \  }}}| 
                    |d           | 
                    |d           |                    d          }t          rJt          d           t          |           t          d           t          |           t                       |S )Nwzutf-8)encodingr   r   z

--- code ---z
--- stdout ---)textwrapdedentstripopenr   TESTFN
addCleanupunlinkwriter   assertEqualdecoder   r
   )selfcodefdstatusstdoutstderrresults          r   run_codezTestLLTrace.run_code   sP   t$$**,,)"C'::: 	bOOI,i.>???HHTNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 "2)2B!C!C%%%###w'' 	$%%%$KKK$%%%&MMMGGGs   A BBBc                    |                      d          }|                     d|           |                     d|           |                     d|           |                     d|           |                     d|           |                     d|           |                     d|           |                     d	|           |                     d
|           d S )Na  
            def dont_trace_1():
                a = "a"
                a = 10 * a
            def trace_me():
                for i in range(3):
                    +i
            def dont_trace_2():
                x = 42
                y = -x
            dont_trace_1()
            __lltrace__ = 1
            trace_me()
            del __lltrace__
            dont_trace_2()
        GET_ITERFOR_ITERUNARY_POSITIVEPOP_TOP	BINARY_OPUNARY_NEGATIVEz'trace_me' in module '__main__'dont_trace_1z'dont_trace_2' in module)r(   assertInassertNotInr!   r%   s     r   test_lltracezTestLLTrace.test_lltrace'   s          	j&)))j&)))&///i(((f---)62227@@@0003V<<<<<r   c                    |                      d          }|                     d|           |                     d|           |                     d|           |                     d|           d t          j        t                    D             }|                                D ]}|                    d          \  }}}|st          |          }|                                }t          |          dk    r|\  }}t          |          }n|\  }d }| 
                    ||         j        |           | 
                    ||         j        |           d S )	Nz
            from test import test_lltrace
            test_lltrace.__lltrace__ = 1
            test_lltrace.example()
        z''example' in module 'test.test_lltrace'
LOAD_CONSTr+   zthis is an examplec                     i | ]
}|j         |S  )offset).0r   s     r   
<dictcomp>z=TestLLTrace.test_lltrace_different_module.<locals>.<dictcomp>O   s    HHHQQXqHHHr   :   )r(   r1   disget_instructionsr   
splitlines	partitionintsplitlenr   opnamearg)	r!   r%   	instr_mapliner9   colonopname_opargrE   opargs	            r   test_lltrace_different_modulez)TestLLTrace.test_lltrace_different_moduleC   sg       
 	?HHHlF+++j&)))*F333 IH#*>w*G*GHHH	%%'' 	; 	;D*...*=*='FE< [[F'--//L<  A%% ,E

(	Yv.5v>>>Yv.2E::::	; 	;r   c                 \    |                      d          }|                     d|           d S )Nz
            import code

            console = code.InteractiveConsole()
            console.push('__lltrace__ = 1')
            console.push('a = [1, 2, 3]')
            console.push('a[0] = 1')
            print('unreachable if bug exists')
        zunreachable if bug exists)r(   r1   r3   s     r   1test_lltrace_does_not_crash_on_subscript_operatorz=TestLLTrace.test_lltrace_does_not_crash_on_subscript_operator_   s9    
      	16:::::r   N)__name__
__module____qualname__r(   r4   rL   rN   r8   r   r   r   r      sP          "= = =8; ; ;8; ; ; ; ;r   r   __main__)r>   sysr   unittesttest.supportr   r   test.support.script_helperr   r   hasattrPy_DEBUG
skipUnlessTestCaser   rO   mainr8   r   r   <module>r\      s    



 



   + + + + + + + + 7 7 7 7 7 7   73*++X:;;Y; Y; Y; Y; Y;(# Y; Y; <;Y;v zHMOOOOO r   