
    z%ia                     v   d dl Z d dlZd dlZd dl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mZ d Z e       \  ZZZedk  r ej"                  dedede       ej$                         s ej"                  d	       ej&                  d
      xs d ej&                  d      xs dv r ej"                  d      e j(                  j+                  e j(                  j-                  ej.                        d      ZdZd Z e       Zd Z ed      \  ZZes ej"                  d      dev r ej"                  d       edej.                        \  ZZdev r%dZ  ej"                  e ejC                         z         d Z" e"       Z#dZ$ ejJ                  e	jL                  d       G d dejN                               Z( G d d e(      Z) ejJ                   e       d!       G d" d#e(             Z*d$Z+ G d% d&e(      Z, G d' d(e(      Z- G d) d*e(      Z. G d+ d,e(      Z/d- Z0e1d.k(  r ejd                          yy)/    N)support)findfilepython_is_optimizedc            
      >   	 g d} t        j                  | t         j                  t         j                  d      }|5  |j                         \  }}d d d        |j                  r0t        ddj                  |       d|j                   dd      	 t        j                  d
      }|t        d|z        |t        |j                  d            t        |j                  d            fS # 1 sw Y   xY w# t        $ r t        j                  d	      w xY w)N)gdb-nxz	--versionT)stdoutstderruniversal_newlineszCommand  z failed with exit code z	: stdout=z stderr=zCouldn't find gdb on the pathz ^(?:GNU|HP) gdb.*?\b(\d+)\.(\d+)zunable to parse GDB version: %r      )
subprocessPopenPIPEcommunicate
returncode	ExceptionjoinOSErrorunittestSkipTestresearchintgroup)cmdprocversionr
   matchs        A/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/test/test_gdb.pyget_gdb_versionr"      s#   A)'1'1379  	1"..0OGV	1 ??hsxx}&7 8..2oo-> ?&&-[
D E E  II97CE}9GCDDSQ(#ekk!n*=>>+	1 	1  A  ?@@As#   ;C= C1AC= 1C:6C= =D   z=gdb versions before 7.0 didn't support python embedding. Saw .z:
z3test_gdb only works on source builds at the moment.PGO_PROF_USE_FLAGxxxPY_CORE_CFLAGS z&test_gdb is not reliable on PGO buildszpython-gdb.py123c                      t        j                  d      } | sy| j                         }d|v xr t        d |D              S )NCFLAGSFz-mcetc              3   f   K   | ])  }|j                  d       xr |j                  d        + yw)z-fcf-protection)z=nonez=returnN)
startswithendswith).0flags     r!   	<genexpr>z!cet_protection.<locals>.<genexpr>M   s>      ' __%67 A!]]+?@@A 's   /1)	sysconfigget_config_varsplitany)cflagsflagss     r!   cet_protectionr8   E   sL    %%h/FLLNE  ' ' %' '(    c                     |r0t         j                  j                         }|j                  |       nd}d}t        t
        fdk\  r|ddt        z   fz  }t        j                  || z   t        j                  t        j                  t        j                  |      }|5  |j                         \  }}ddd       j                  dd      j                  dd      fS # 1 sw Y   -xY w)	zRuns gdb in --batch mode with the additional arguments given by *args.

    Returns its (stdout, stderr) decoded from utf-8 using the replace handler.
    N)r   z--batchr   r#      z-iexzadd-auto-load-safe-path )stdinr	   r
   envzutf-8replace)osenvironcopyupdategdb_major_versiongdb_minor_versioncheckout_hook_pathr   r   r   r   decode)argsenv_varsr>   base_cmdr   outerrs          r!   run_gdbrM   U   s    
 jjoo

8 )H,-7V7:LLMMHtO #-//#-??#-?? #%D 
 &##%S&::gy)3::gy+III& &s   CC&z9--eval-command=python import sys; print(sys.version_info)z*gdb not built with embedded python supportzmajor=2zgdb built with Python 2--argszauto-loading has been declinedz3gdb security settings prevent use of custom hooks: c                      t        d      \  } }t        j                  d|       }|st        j                  d      |j                  d      j                  d      }d|v S )Nz+--eval-command=python print(dir(gdb.Frame))z.*\[(.*)\].*z1Unable to parse output from gdb.Frame.select testr   z, z'select')rM   r   r    r   r   r   r4   )r	   _mgdb_frame_dirs       r!   gdb_has_frame_selectrS   ~   sY    EFIFA
&)A STTGGAJ$$T*M&&r9   
builtin_idznot useful for PGOc                   B    e Zd ZdZddedddfdZ	 	 d	dZd Zd Zd Z	y)
DebuggerTestsz(Test that the debugger can debug Python.NFc                 H   dd|z  ddg}t         t        fdk\  r|dgz  }|rt        r|dgz  }||z  }n|dgz  }|D cg c]  }d	|z  	 }	}|	d
t        j                  gz  }	|	j                  t        j                                |s|	dgz  }	|r|	d|gz  }	n|r|	|gz  }	t        |	dt        i\  }
}|s0|j                         D ]  }t        |t        j                          d|v rt        j                  d      dD ]  }||
v st        j                  |d       |
S c c}w )z
        Run 'python -c SOURCE' under gdb with a breakpoint.

        Support injecting commands after the breakpoint is reached

        Returns the stdout from gdb

        cmds_after_breakpoint: if provided, a list of strings: gdb commands
        zset breakpoint pending yeszbreak %szset print address offrunr;   zset print entry-values nonext	backtracez--eval-command=%srN   z-Sz-cPYTHONHASHSEED)filezPC not savedzKgdb cannot walk the frame object because the Program Counter is not present)z!(frame information optimized out)z*Unable to read information on python framez)(unable to read python frame information)z,Backtrace stopped: frame did not save the PCz ?? ()z found in gdb output)rD   rE   CET_PROTECTIONsys
executableextendr   _args_from_interpreter_flagsrM   r[   
splitlinesprintr
   r   r   )selfsourcescript
breakpointcmds_after_breakpointimport_siteignore_stderrcommandsr   rH   rK   rL   linepatterns                 r!   get_stack_tracezDebuggerTests.get_stack_trace   s}   8 1+ ,* 01V;455H 
 VH$--H%H
 6>>c#c)>>! 	!J;;=>TFNDT6N"DVHD D@@S( -d,- S ## %3 4 4
 	LG #~''7+5I(JKK!	L$ 
g ?s   Dc                     |xs dg}| j                  |t        ||      }t        j                  d|t        j                        }|s| j                  d|d|       |j                  d      |fS )Nzbacktrace 1)rg   rh   ri   zS#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)?\)\s+at\s+\S*[A-Za-z]+/[A-Za-z0-9_-]+\.czUnexpected gdb output: 
r   )rn   BREAKPOINT_FNr   r   DOTALLfailr   )rd   re   rh   ri   
gdb_outputrQ   s         r!   get_gdb_reprzDebuggerTests.get_gdb_repr  sz      !6 H-))&]@U6A * C
 II6 		# IIZPQwwqz:%%r9   c                 R    | j                  |j                  |      |d|       y)z9Ensure that the given "actual" string ends with "exp_end"z did not end with msgN)
assertTruer.   )rd   actualexp_ends      r!   assertEndsWithzDebuggerTests.assertEndsWith+  s'    08>H 	 	Jr9   c                     t        j                  ||t         j                        }|s| j                  |d|       y y )Nz did not match rw   )r   r    rr   rs   )rd   rz   rm   rQ   s       r!   assertMultilineMatchesz$DebuggerTests.assertMultilineMatches0  s3    HHWfbii0II67CID r9   c                     t        d      S )Nzgdb_sample.py)r   rd   s    r!   get_sample_scriptzDebuggerTests.get_sample_script5  s    ((r9   )NF)
__name__
__module____qualname____doc__rq   rn   ru   r|   r~   r    r9   r!   rV   rV      s>     3%)$#0.2$)&+	up ,0!&"&HJ
E
)r9   rV   c                      e Zd Zd Zd dZ ej                  d      d        Zd Zd Z	d Z
 ej                  d      d	        Z ej                  d      d
        Zd Z ej                  d      d        Z ej                  d      d        Zd Zd Zd Zd Zd dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!y)!PrettyPrintTestsc                 T    | j                  d      }| j                  t        |v        y )Nid(42))rn   ry   rq   rd   rt   s     r!   test_getting_backtracez'PrettyPrintTests.test_getting_backtrace9  s#    ))(3
34r9   Nc           	          | j                  dt        |      z   dz         \  }}|st        |      }| j                  |||d|d|       y )Nzid()z did not equal expected z; full output was:
)ru   asciireprassertEqual)rd   valexp_reprgdb_reprrt   s        r!   assertGdbReprzPrettyPrintTests.assertGdbRepr=  sQ      $00s1Cc1IJ*CyH8%x=	?r9   cpuc                     | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y)z0Verify the pretty-printing of various int values*   r   il    J)l  I5 Nr   r   s    r!   test_intzPrettyPrintTests.test_intG  sK     	212=),-r9   c                 j    | j                  d       | j                  d       | j                  d       y)z2Verify the pretty-printing of True, False and NoneTFNr   r   s    r!   test_singletonsz PrettyPrintTests.test_singletonsP  s,    4 5!4 r9   c                 x    | j                  i        | j                  ddid       | j                  dddd       y)z*Verify the pretty-printing of dictionariesfoobarz{'foo': 'bar'}r   )r   douglasz{'foo': 'bar', 'douglas': 42}Nr   r   s    r!   
test_dictszPrettyPrintTests.test_dictsV  s;    2E5>+;<5R8:YZr9   c                 l    | j                  g        | j                  t        t        d                   y)z#Verify the pretty-printing of lists   N)r   listranger   s    r!   
test_listszPrettyPrintTests.test_lists]  s&    24a>*r9   c                    | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  t        t        d      D cg c]  }| c}             yc c}w )z#Verify the pretty-printing of bytesr9   s(   And now for something hopefully the sames7   string with embedded NUL here   and then some more texts7   this is a tab:	 this is a slash-N:
 this is a slash-R:s!   this is byte 255: and byte 128:   N)r   bytesr   )rd   bs     r!   
test_byteszPrettyPrintTests.test_bytesb  sy     	3FGVW 4 	
 	EF5U3Z!8!!89:!8s   3	Bc                     t        dd      \  }}|j                         |sst        d|        fd} j                  d        j                  d        j                  d        |d        |d	        |t	        d
             y)z-Verify the pretty-printing of unicode stringsz--eval-commandz:python import locale; print(locale.getpreferredencoding())zFunable to determine the preferred encoding of embedded Python in GDB: c                     	 | j                         j                  |        y # t        $ r j                  | t        |              Y y w xY wN)encoder   UnicodeEncodeErrorr   )textencodingrd   s    r!   
check_reprz1PrettyPrintTests.test_strings.<locals>.check_repr  sI    )H% ""4( & 6""4t56s   & $AAr(   z(And now for something hopefully the samez7string with embedded NUL here   and then some more textu   ☠u   文字化けi! N)rM   rstripRuntimeErrorr   chr)rd   rK   rL   r   r   s   `   @r!   test_stringszPrettyPrintTests.test_stringsq  s     HJS ::<h..1U45 5	) 	2EFUV 	8
 	-. 	3w< r9   c                 ~    | j                  t               d       | j                  dd       | j                  d       y)z$Verify the pretty-printing of tuplesz())r   z(1,))r   r   bazN)r   tupler   s    r!   test_tupleszPrettyPrintTests.test_tuples  s3    57D)4(01r9   c                    t         t        fdk  r| j                  d       | j                  t	               d       | j                  t	        dg      d       t
        j                  j                  s:| j                  t	        ddg      d       | j                  t	        g d      d	       | j                  d
      \  }}| j                  |d       y)z"Verify the pretty-printing of setsr#      z.pretty-printing of sets needs gdb 7.3 or laterzset()az{'a'}r   z
{'a', 'b'}r<   r      z	{4, 5, 6}z&s = set(['a','b'])
s.remove('a')
id(s)z{'b'}N)
rD   rE   skipTestr   setr^   r7   ignore_environmentru   r   rd   r   rt   s      r!   	test_setszPrettyPrintTests.test_sets  s     01F:MMJK35'*3u:w/yy++sC:=s9~{;  $00 2	  
* 	7+r9   c                 Z   t         t        fdk  r| j                  d       | j                  t	               d       | j                  t	        dg      d       t
        j                  j                  s;| j                  t	        ddg      d       | j                  t	        g d      d	       y
y
)z(Verify the pretty-printing of frozensetsr   z4pretty-printing of frozensets needs gdb 7.3 or laterzfrozenset()r   zfrozenset({'a'})r   zfrozenset({'a', 'b'})r   zfrozenset({4, 5, 6})N)rD   rE   r   r   	frozensetr^   r7   r   r   s    r!   test_frozensetsz PrettyPrintTests.test_frozensets  s     01F:MMPQ9;69cU+-?@yy++y#s46MNy35KL ,r9   c                     | j                  d      \  }}| j                  |d       | j                  d      \  }}| j                  |d       y )NzR
try:
    raise RuntimeError("I am an error")
except RuntimeError as e:
    id(e)
zRuntimeError('I am an error',)z=
try:
    a = 1 / 0
except ZeroDivisionError as e:
    id(e)
z&ZeroDivisionError('division by zero',)ru   r   r   s      r!   test_exceptionsz PrettyPrintTests.test_exceptions  sc    #00 2  * 	9	;
  $00 2  * 	A	Cr9   c                     | j                  d      \  }}t        j                  d|      }| j                  |d|z         y)z7Verify the pretty-printing of new-style class instancesz8
class Foo:
    pass
foo = Foo()
foo.an_int = 42
id(foo)*<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>'Unexpected new-style class rendering %rrw   Nru   r   r    ry   rd   r   rt   rQ   s       r!   test_modern_classz"PrettyPrintTests.test_modern_class  sK    #00 2  * HHBHMEP 	 	Rr9   c                     | j                  d      \  }}t        j                  d|      }| j                  |d|z         y)z<Verify the pretty-printing of an instance of a list subclasszO
class Foo(list):
    pass
foo = Foo()
foo += [1, 2, 3]
foo.an_int = 42
id(foo)r   r   rw   Nr   r   s       r!   test_subclassing_listz&PrettyPrintTests.test_subclassing_list  sK    #00 2  * HHBHMEP 	 	Rr9   c                     | j                  d      \  }}t        j                  d|      }| j                  |d|z         y)z=Verify the pretty-printing of an instance of a tuple subclasszH
class Foo(tuple):
    pass
foo = Foo((1, 2, 3))
foo.an_int = 42
id(foo)r   r   rw   Nr   r   s       r!   test_subclassing_tuplez'PrettyPrintTests.test_subclassing_tuple  sM      $00 2  * HHBHMEP 	 	Rr9   c                     |r|dg}ndg}| j                  ||      \  }}|r||k(  ryd}t        j                  ||      }|s| j                  d|d|       yy)zRun Python under gdb, corrupting variables in the inferior process
        immediately before taking a backtrace.

        Verify that the variable's representation is the expected failsafe
        representationrZ   rh   Nz<.* at remote 0x-?[0-9a-f]+>Unexpected gdb representation: rp   )ru   r   r    rs   )	rd   re   
corruptionexpreprrh   r   rt   rm   rQ   s	            r!   
assertSanezPrettyPrintTests.assertSane  s     #-{";!#.-! f4I  K 	* 7"  1HHWh'II#Z1 2 r9   c                 X    | j                  dddg      \  }}| j                  |d       y)z2Ensure that a NULL PyObject* is handled gracefullyr   zset variable v=0rZ   r   0x0Nr   r   s      r!   test_NULL_ptrzPrettyPrintTests.test_NULL_ptr  sA     h5G5@5B  C 	* 	5)r9   c                 (    | j                  dd       y)z?Ensure that a PyObject* with NULL ob_type is handled gracefullyr   zset v->ob_type=0Nr   r   s    r!   test_NULL_ob_typez"PrettyPrintTests.test_NULL_ob_type)  s    *	,r9   c                 ,    | j                  ddd       y)zDEnsure that a PyObject* with a corrupt ob_type is handled gracefullyr   zset v->ob_type=0xDEADBEEF42r   Nr   r   s    r!   test_corrupt_ob_typez%PrettyPrintTests.test_corrupt_ob_type.  s    3 $ 	 	&r9   c                 ,    | j                  ddd       y)zDEnsure that a PyObject* with a type with corrupt tp_flags is handledr   zset v->ob_type->tp_flags=0x0r   r   Nr   r   s    r!   test_corrupt_tp_flagsz&PrettyPrintTests.test_corrupt_tp_flags4  s    6 $ 	 	&r9   c                 ,    | j                  ddd       y)zCEnsure that a PyObject* with a type with corrupt tp_name is handledr   z"set v->ob_type->tp_name=0xDEADBEEFr   r   Nr   r   s    r!   test_corrupt_tp_namez%PrettyPrintTests.test_corrupt_tp_name:  s    < $ 	 	&r9   c                     t         j                  j                  r| j                  d       | j	                  dd      \  }}t        j                  d|      }| j                  |d|z         y)	zAEnsure that the new-style class _Helper in site.py can be handledz(need site module, but -S option was usedzid(__builtins__.help)T)ri   z%<_Helper\(\) at remote 0x-?[0-9a-f]+>zUnexpected rendering %rrw   N)r^   r7   no_siter   ru   r   r    ry   r   s       r!   test_builtins_helpz#PrettyPrintTests.test_builtins_help@  si     99MMDE  $001HVZ0[*HH=xH5@ 	 	Br9   c                     | j                  d      \  }}| j                  |d       | j                  d      \  }}| j                  |d       y)zbEnsure that a reference loop involving a list doesn't lead proxyval
        into an infinite loop:z#a = [3, 4, 5] ; a.append(a) ; id(a)z[3, 4, 5, [...]]z-a = [3, 4, 5] ; b = [a] ; a.append(b) ; id(a)z[3, 4, 5, [[...]]]Nr   r   s      r!   test_selfreferential_listz*PrettyPrintTests.test_selfreferential_listN  sX     CD 	*#56 MN 	*#78r9   c                 P    | j                  d      \  }}| j                  |d       y)zbEnsure that a reference loop involving a dict doesn't lead proxyval
        into an infinite loop:z-a = {} ; b = {'bar':a} ; a['foo'] = b ; id(a)z{'foo': {'bar': {...}}}Nr   r   s      r!   test_selfreferential_dictz*PrettyPrintTests.test_selfreferential_dictY  s/     MN 	* 	#<=r9   c                     | j                  d      \  }}| j                  t        j                  d|      d|d|       y )Nz:
class Foo:
    pass
foo = Foo()
foo.an_attr = foo
id(foo)1<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>r   rp   ru   ry   r   r    r   s      r!   'test_selfreferential_old_style_instancez8PrettyPrintTests.test_selfreferential_old_style_instancea  sI       	* 	!U!)+ &z3	4r9   c                    | j                  d      \  }}| j                  t        j                  d|      d|d|       | j                  d      \  }}| j                  t        j                  d|      d|d|       y )NzB
class Foo(object):
    pass
foo = Foo()
foo.an_attr = foo
id(foo)r   r   rp   zR
class Foo(object):
    pass
a = Foo()
b = Foo()
a.an_attr = b
b.an_attr = a
id(a)zZ<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>\) at remote 0x-?[0-9a-f]+>r   r   s      r!   'test_selfreferential_new_style_instancez8PrettyPrintTests.test_selfreferential_new_style_instancen  s       	* 	!U!)+ &z3	4  	 
 	* 	!~!)+ &z3	4r9   c                     | j                  d      \  }}| j                  |d       | j                  t        |      dt        d      z          y)z)Verify that very long output is truncatedzid(list(range(1000)))a  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226...(truncated)i   z...(truncated)N)ru   r   lenr   s      r!   test_truncationz PrettyPrintTests.test_truncation  sQ    #001HI*7	8, 	X$4 55	7r9   c                     | j                  d      \  }}| j                  t        j                  d|      d|d|       y )Nz$import sys; id(sys.stdout.readlines)zO<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>r   rp   r   r   s      r!   test_builtin_methodz$PrettyPrintTests.test_builtin_method  sA    #001WX*!s!)+ &z3	4r9   c                     | j                  dddg      }| j                  t        j                  d|t        j                        d|d|       y )NzQ
import sys
def foo(a, b, c):
    return sys._getframe(0)

f = foo(3, 4, 5)
id(f)rT   zprint (PyFrameObject*)v)rg   rh   zK.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 4, in foo \(a=3.*r   rp   )rn   ry   r   r    rr   r   s     r!   test_frameszPrettyPrintTests.test_frames  s[    )) +	 6BAZ@[ * 	,
 	!o!+!#, DNzZ	\r9   r   )"r   r   r   r   r   r   requires_resourcer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r9   r!   r   r   8  s)   5? Wu%. &.![+
 Wu%; &; Wu%*! &*!X2 Wu%, &,$ Wu%	M &	MC,
RRR2:*,
&&&B	9>446784\r9   r   &Python was compiled with optimizationsc                   $    e Zd Zd Zd Zd Zd Zy)PyListTestsc                 (    | j                  ||       y r   )r|   )rd   expectedrz   s      r!   assertListingzPyListTests.assertListing  s    FH-r9   c                 l    | j                  | j                         dg      }| j                  d|       y)z'Verify that the "py-list" command workszpy-listrf   rh   z   5    
   6    def bar(a, b, c):
   7        baz(a, b, c)
   8    
   9    def baz(*args):
 >10        id(42)
  11    
  12    foo(1, 2, 3)
Nrn   r   r  rd   bts     r!   test_basic_commandzPyListTests.test_basic_command  sB    !!)?)?)A9B " E 	 4 	r9   c                 l    | j                  | j                         dg      }| j                  d|       y)z7Verify the "py-list" command with one absolute argumentz	py-list 9r  zI   9    def baz(*args):
 >10        id(42)
  11    
  12    foo(1, 2, 3)
Nr  r	  s     r!   test_one_abs_argzPyListTests.test_one_abs_arg  sB    !!)?)?)A9D " G 	 4 		r9   c                 l    | j                  | j                         dg      }| j                  d|       y)z8Verify the "py-list" command with two absolute argumentszpy-list 1,3r  zR   1    # Sample script for use by test_gdb.py
   2    
   3    def foo(a, b, c):
Nr  r	  s     r!   test_two_abs_argszPyListTests.test_two_abs_args  sB    !!)?)?)A9F " I 	 9 	r9   N)r   r   r   r  r  r  r  r   r9   r!   r  r    s    .	r9   r  z

from _testcapi import pyobject_fastcall

def foo(a, b, c):
    bar(a, b, c)

def bar(a, b, c):
    pyobject_fastcall(baz, (a, b, c))

def baz(*args):
    id(42)

foo(1, 2, 3)

c                   @   e Zd Z ej                  ed       ej                   e       d      d               Z ej                  ed      d        Z	 ej                  ed      d        Z
 ej                  ed       ej                   e       d      d               Zy)StackNavigationTests$test requires py-up/py-down commandsr   c                 Z    | j                  t        ddg      }| j                  |d       y)z%Verify that the "py-up" command workspy-upre   rh   z^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
#[0-9]+ <built-in method pyobject_fastcall of module object at remote 0x[0-9a-f]+>
$Nrn   SAMPLE_WITH_C_CALLr~   r	  s     r!   test_pyup_commandz&StackNavigationTests.test_pyup_command  s:    
 !!);9@'8J " L##B%	r9   c                 l    | j                  | j                         dg      }| j                  |d       y)z7Verify handling of "py-down" at the bottom of the stackpy-downr  z$Unable to find a newer python frame
Nrn   r   r|   r	  s     r!   test_down_at_bottomz(StackNavigationTests.test_down_at_bottom  s>     !!)?)?)A9B " EBC	Er9   c                 r    | j                  | j                         dgdz        }| j                  |d       y)z2Verify handling of "py-up" at the top of the stackr  r   r  z%Unable to find an older python frame
Nr  r	  s     r!   test_up_at_topz#StackNavigationTests.test_up_at_top  sB     !!)?)?)A9@	A " GBD	Fr9   c                 Z    | j                  t        g d      }| j                  |d       y)z$Verify "py-up" followed by "py-down")r  r  r  r  a  ^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
#[0-9]+ <built-in method pyobject_fastcall of module object at remote 0x[0-9a-f]+>
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
$Nr  r	  s     r!   test_up_then_downz&StackNavigationTests.test_up_then_down  s5    
 !!);8U " W##B%	r9   N)r   r   r   r   
skipUnlessHAS_PYUP_PYDOWNskipIfr   r  r  r  r   r   r9   r!   r  r    s    X*PQX__(*=?? R X*PQE RE X*PQF RF X*PQX__(*=?	? R	r9   r  c                      e Zd Z ej                   e       d      d        Z ej                   e       d      d        Z ej                   e       d       ej                  d      d               Z
 ej                   e       d      d        Z ej                   e       d       ej                  d      d               Z ej                   e       d      d        Zy	)
	PyBtTestsr   c                 l    | j                  | j                         dg      }| j                  |d       y)z%Verify that the "py-bt" command workspy-btr  aL  ^.*
Traceback \(most recent call first\):
  <built-in method id of module object .*>
  File ".*gdb_sample.py", line 10, in baz
    id\(42\)
  File ".*gdb_sample.py", line 7, in bar
    baz\(a, b, c\)
  File ".*gdb_sample.py", line 4, in foo
    bar\(a=a, b=b, c=c\)
  File ".*gdb_sample.py", line 12, in <module>
    foo\(1, 2, 3\)
Nrn   r   r~   r	  s     r!   test_btzPyBtTests.test_bt%  s?     !!)?)?)A9@	 " C##B%	r9   c                 l    | j                  | j                         dg      }| j                  |d       y)z*Verify that the "py-bt-full" command works
py-bt-fullr  aD  ^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
    baz\(a, b, c\)
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\)
    bar\(a=a, b=b, c=c\)
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 12, in <module> \(\)
    foo\(1, 2, 3\)
Nr(  r	  s     r!   test_bt_fullzPyBtTests.test_bt_full9  s?     !!)?)?)A9E " H##B%	r9   r   c                     d}| j                  |dg      }| j                  d|       | j                  |dg      }| j                  d|       y)zBVerify that "py-bt" indicates threads that are waiting for the GILaN  
from threading import Thread

class TestThread(Thread):
    # These threads would run forever, but we'll interrupt things with the
    # debugger
    def run(self):
        i = 0
        while 1:
             i += 1

t = {}
for i in range(4):
   t[i] = TestThread()
   t[i].start()

# Trigger a breakpoint on the main thread
id(42)

zthread apply all py-btr   zWaiting for the GILzthread apply all py-bt-fullNrn   assertInrd   r   rt   s      r!   test_threadszPyBtTests.test_threadsI  sg    
* ))#AY@Z * \
+Z8 ))#A^@_ * a
+Z8r9   c                     d}| j                  |g d      }| j                  d|       | j                  |g d      }| j                  d|       y)z?Verify that "py-bt" indicates if a thread is garbage-collectingzRfrom gc import collect
id(42)
def foo():
    collect()
def bar():
    foo()
bar()
)break update_refscontinuer'  r   zGarbage-collecting)r3  r4  r+  Nr.  r0  s      r!   test_gczPyBtTests.test_gcl  sc     ))#@j * ,
 	*J7 ))#@o * ,
 	*J7r9   c                    d}dD ]  \  }}dD ]  }| j                  | d|       5  t        j                  d| d| d| d      }| j                  ||dd	gd
      }| j	                  d| |       | j                  ||dgd
      }|}|t        j                  d|       z  }| j                  ||       ddd         y# 1 sw Y   xY w)zAVerify that "py-bt" displays invocations of PyCFunction instancesz#(1|2)))meth_varargsr(   )meth_varargs_keywordsr(   )meth_oz[])meth_noargsr(   )meth_fastcallr(   )meth_fastcall_keywordsr(   )	_testcapiz_testcapi.MethClassz_testcapi.MethClass()z_testcapi.MethStatic()r$   zi
                        import _testcapi
                        def foo():
                            (zy)
                        def bar():
                            foo()
                        bar()
                    r
  r'  T)rg   rh   rj   z<built-in method r+  z <built-in method N)subTesttextwrapdedentrn   r/  r   escapeassertRegex)rd   expected_frame	func_namerH   objr   rt   regexs           r!   test_pycfunctionzPyBtTests.test_pycfunction  s,   " # 
 0	8OIt (8 \\SE9+"67 8"// / !E9+Qtf 5+ C "&!5!5#,/3Wo '+ "6 "J MM$5i["A:N "&!5!5#,/;n '+ "6 "J +ERYY);I;'GHHE$$Z7?8 8(80	8"8 8s   BCCc                     t        j                  d      }ddg}t        r|j                  d       |j                  d       | j	                  ||      }| j                  |d       y )Nz
            class MyList(list):
                def __init__(self):
                    super(*[]).__init__()   # wrapper_call()

            id("first break point")
            l = MyList()
        zbreak wrapper_callr4  rY   r'  r   z1<method-wrapper u?'__init__' of MyList object at )r@  rA  r]   appendrn   rC  )rd   r   rh   rt   s       r!   test_wrapper_callzPyBtTests.test_wrapper_call  sv     oo   "6z B "((0$$W- ))#@U * W
M	Or9   N)r   r   r   r   r#  r   r)  r,  r   r   r1  r5  rH  rK  r   r9   r!   r%  r%  $  s   X__(*=??$ X__(*=?? X__(*=?Wu%9 &?9@ X__(*=?
8?
8, X__(*=?Wu%88 &?88t X__(*=?O?Or9   r%  c                   (   e Zd Z ej                   e       d      d        Z ej                   e       d       ej                  ed      d               Z	 ej                   e       d      d        Z
 ej                   e       d      d        Zy)PyPrintTestsr   c                 Z    | j                  t        ddg      }| j                  |d       y)z(Verify that the "py-print" command worksr  zpy-print argsr  z".*\nlocal 'args' = \(1, 2, 3\)\n.*Nr  r	  s     r!   r  zPyPrintTests.test_basic_command  s9     !!);9@/8R " T##B$I	Kr9   r  c                 Z    | j                  t        g d      }| j                  |d       y )N)r  r  z
py-print cz
py-print bz
py-print ar  z3.*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*r  r	  s     r!   test_print_after_upz PyPrintTests.test_print_after_up  s4     !!);8t " v##B$Z	\r9   c                 n    | j                  | j                         ddg      }| j                  |d       y )Nr  zpy-print __name__r  z&.*\nglobal '__name__' = '__main__'\n.*r(  r	  s     r!   test_printing_globalz!PyPrintTests.test_printing_global  sB     !!)?)?)A9@BU8V " X##B$M	Or9   c                 n    | j                  | j                         ddg      }| j                  |d       y )Nr  zpy-print lenr  zV.*\nbuiltin 'len' = <built-in method len of module object at remote 0x-?[0-9a-f]+>\n.*r(  r	  s     r!   test_printing_builtinz"PyPrintTests.test_printing_builtin  sA     !!)?)?)A9@.8Q " S##B$}	r9   N)r   r   r   r   r#  r   r  r!  r"  rP  rR  rT  r   r9   r!   rM  rM    s    X__(*=?K?K X__(*=?X*PQ\ R?\ X__(*=?O?O X__(*=??r9   rM  c                       e Zd Z ej                   e       d      d        Z ej                  ed       ej                   e       d      d               Z	y)PyLocalsTestsr   c                 n    | j                  | j                         ddg      }| j                  |d       y )Nr  	py-localsr  z.*\nargs = \(1, 2, 3\)\n.*r(  r	  s     r!   r  z PyLocalsTests.test_basic_command
  sA     !!)?)?)A9@+8N " P##B$A	Cr9   r  c                 n    | j                  | j                         g d      }| j                  |d       y )N)r  r  rX  r  z<^.*
Locals for foo
a = 1
b = 2
c = 3
Locals for <module>
.*$r(  r	  s     r!   test_locals_after_upz"PyLocalsTests.test_locals_after_up  s=     !!)?)?)A8W " Y##B%	r9   N)
r   r   r   r   r#  r   r  r!  r"  rZ  r   r9   r!   rV  rV  	  sk    X__(*=?C?C X*PQX__(*=?
? R
r9   rV  c                      t         j                  rBt        dt        dt        d       t
        j                         D ]  } t        d| z           y y )NzGDB version r$   :z    )r   verboserc   rD   rE   gdb_versionrb   )rl   s    r!   setUpModuler_  "  sA    &79JKL**, 	"D'D.!	" r9   __main__)3r@   platformr   r   r^   r2   r@  r   testr   test.supportr   r   r"   r^  rD   rE   r   is_python_buildr3   pathr   dirnamer_   rF   r[   r8   r]   rM   gdbpy_versionrP   gdbpy_errorsrx   r   rS   r"  rq   r#  PGOTestCaserV   r   r  r  r  r%  rM  rV  r_  r   mainr   r9   r!   <module>rl     s   
  	  
     6?< 5D4E 1 1q
(

02C*, - -
 !y  "
(

Q
RRY12;eY./527
(

D
EE WW\\"''//#.."A"13  
(  !J6 VW q
(

H
II
(

5
66 (CNN3<#|3
?C
(

C,"5"5"77
88' '(23j)H%% j) 4j)XB\} B\H $&9;&- &;&P $*= *X@O @OD!= !FM 2" zHMMO r9   