
    daf                         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 d Z	 ej                  ej                  d       G d dej                               Zed	k(  r ej                          yy)
    N)support)	os_helper)assert_python_okc                  j    g } t        d      D ]  }| j                  |        d} d}t        | |       y )Nr   zthis isz
an example)rangeappendprint)xiys      ,/root/Python-3.12.4/Lib/test/test_lltrace.pyexampler   	   s8    
A1X 	AA	!QK    zlltrace requires Py_DEBUGc                   $    e Zd Zd Zd Zd Zd Zy)TestLLTracec                 \   t        j                  |      j                         }t        t        j
                  dd      5 }| j                  t        j                  t        j
                         |j                  |       d d d        t        t        j
                        \  }}}| j                  |d       | j                  |d       |j                  d      }t        j                  r6t        d       t        |       t        d       t        |       t                |S # 1 sw Y   xY w)Nwzutf-8)encodingr   r   z

--- code ---z
--- stdout ---)textwrapdedentstripopenr   TESTFN
addCleanupunlinkwriter   assertEqualdecoder   verboser	   )selfcodefdstatusstdoutstderrresults          r   run_codezTestLLTrace.run_code   s    t$**,)""C': 	bOOI,,i.>.>?HHTN	 "2)2B2B!C%#w'??$%$K$%&MG	 	s    A D""D+c                 j   | j                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d	|       | j                  d
|       y )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CALL_INTRINSIC_1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&)(&1i(f-)627@03V<r   c                 |   | j                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       t        j                  t        d      D ci c]  }|j
                  | }}|j                         D ]  }|j                  d      \  }}}|st        |      }|j                         }t        |      d	k(  r|\  }}	t        |	      }	n|\  }d }	| j                  ||   j                  |       | j                  ||   j                  |	        y c c}w )
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 exampleT)adaptive:   )r'   r0   disget_instructionsr   offset
splitlines	partitionintsplitlenr   opnamearg)
r    r$   r   	instr_mapliner;   colonopname_opargrA   opargs
             r   test_lltrace_different_modulez)TestLLTrace.test_lltrace_different_moduleB   s-      
 	?HlF+j&)*F3 +.*>*>wQU*VWQQXXq[W	W%%' 	;D*...*='FE<[F'--/L< A% ,E
(	Yv.55v>Yv.22E:	; Xs   7D9c                 J    | j                  d      }| j                  d|       y )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'   r0   r2   s     r   1test_lltrace_does_not_crash_on_subscript_operatorz=TestLLTrace.test_lltrace_does_not_crash_on_subscript_operator^   s(    
     	16:r   N)__name__
__module____qualname__r'   r3   rH   rJ    r   r   r   r      s    "=8;8;r   r   __main__)r9   r   unittesttestr   test.supportr   test.support.script_helperr   r   
skipUnlessPy_DEBUGTestCaser   rK   mainrN   r   r   <module>rX      sr    
    " 7 W%%'BCY;(## Y; DY;v zHMMO r   