HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_gdb.cpython-37.pyc
B

��g[��@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZdd�Ze�\ZZZedkr�e�deeef��e��s�e�d��d	e��kr�ejd
kr�e�d��ej�ej�ej�d�Zd
Zdd�Ze�Zdd�Zed�\ZZ e�se�d��edej�\Z Z!de!k�rHdZ"e�e"e!�#���dd�Z$e$�Z%dZ&e�'e
j(d�Gdd�dej)��Z*Gdd�de*�Z+e�'e�d�Gd d!�d!e*��Z,Gd"d#�d#e*�Z-Gd$d%�d%e*�Z.Gd&d'�d'e*�Z/Gd(d)�d)e*�Z0d*d+�Z1e2d,k�re1�dS)-�N)�support)�run_unittest�findfile�python_is_optimizedc	Cs�yndddg}tj|tjtjdd�}|�|��\}}WdQRX|jrltdd�|��d|j�d	|�d
|����Wntk
r�t�	d��YnXt
�d|�}|dkr�td
|��|t|�
d��t|�
d��fS)N�gdbz-nxz	--versionT)�stdout�stderrZuniversal_newlineszCommand � z failed with exit code z	: stdout=z stderr=zCouldn't find gdb on the pathz^GNU gdb.*?\b(\d+)\.(\d+)zunable to parse GDB version: %r��)�
subprocess�Popen�PIPE�communicate�
returncode�	Exception�join�OSError�unittest�SkipTest�re�search�int�group)�cmd�proc�versionr�match�r�)/usr/local/lib/python3.7/test/test_gdb.py�get_gdb_versions 
,r �zFgdb versions before 7.0 didn't support python embedding. Saw %s.%s:
%sz3test_gdb only works on source builds at the moment.ZClang�darwinzDtest_gdb doesn't work correctly when python is built with LLVM clangz
python-gdb.pyZ123cCs4t�d�}|sdS|��}d|ko2tdd�|D��S)NZCFLAGSFz-mcetcss$|]}|�d�o|�d�VqdS)z-fcf-protection)z=nonez=returnN)�
startswith�endswith)�.0�flagrrr�	<genexpr>Msz!cet_protection.<locals>.<genexpr>)�	sysconfigZget_config_var�split�any)Zcflags�flagsrrr�cet_protectionEs
r,c	Os�|rtj��}|�|�nd}d}ttfdkr>|ddtf7}tj||tj	tj	tj	|d�}|�|�
�\}}WdQRX|�dd�|�dd�fS)	z�Runs gdb in --batch mode with the additional arguments given by *args.

    Returns its (stdout, stderr) decoded from utf-8 using the replace handler.
    N)rz--batchz-nx)r!�z-iexzadd-auto-load-safe-path )�stdinrr�envzutf-8�replace)�os�environ�copy�update�gdb_major_version�gdb_minor_version�checkout_hook_pathrr
rr�decode)�argsZenv_varsr/Zbase_cmdr�out�errrrr�run_gdbUs

r<z9--eval-command=python import sys; print(sys.version_info)z*gdb not built with embedded python supportz--argszauto-loading has been declinedz3gdb security settings prevent use of custom hooks: cCs>td�\}}t�d|�}|s&t�d��|�d��d�}d|kS)Nz+--eval-command=python print(dir(gdb.Frame))z.*\[(.*)\].*z1Unable to parse output from gdb.Frame.select testr
z, z'select')r<rrrrrr))r�_�mZ
gdb_frame_dirrrr�gdb_has_frame_select{s
r?�
builtin_idznot useful for PGOc@sFeZdZdZddeddfdd�Zddd�Zdd	�Zd
d�Zdd
�Z	dS)�
DebuggerTestsz(Test that the debugger can debug Python.NFcCsdd|ddg}ttfdkr&|dg7}|rBtr8|dg7}||7}n
|dg7}d	d
�|D�}|dtjg7}|�t���|s�|dg7}|r�|d
|g7}n|r�||g7}t|dt	i�\}}	x|	�
�D]}
t|
tjd�q�Wd|	kr�t
�d��x$dD]}||kr�t
�|�d���q�W|S)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
        zset breakpoint pending yeszbreak %szset print address off�run)r!r-zset print entry-values no�next�	backtracecSsg|]}d|�qS)z--eval-command=%sr)r%rrrr�
<listcomp>�sz1DebuggerTests.get_stack_trace.<locals>.<listcomp>z--argsz-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 found in gdb output)r5r6�CET_PROTECTION�sys�
executable�extendrZ_args_from_interpreter_flagsr<rF�
splitlines�printrrr)�self�source�script�
breakpoint�cmds_after_breakpoint�import_siteZcommandsr9r:r;�line�patternrrr�get_stack_trace�s>








zDebuggerTests.get_stack_tracecCsP|pdg}|j|t||d�}t�d|tj�}|sB|�d||f�|�d�|fS)Nzbacktrace 1)rQrRrSzS#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)?\)\s+at\s+\S*[A-Za-z]+/[A-Za-z0-9_-]+\.czUnexpected gdb output: %r
%sr
)rV�
BREAKPOINT_FNrr�DOTALL�failr)rNrOrRrS�
gdb_outputr>rrr�get_gdb_repr�s

zDebuggerTests.get_gdb_reprcCs |j|�|�d||fd�dS)z9Ensure that the given "actual" string ends with "exp_end"z%r did not end with %r)�msgN)�
assertTruer$)rN�actualZexp_endrrr�assertEndsWithszDebuggerTests.assertEndsWithcCs,t�||tj�}|s(|jd||fd�dS)Nz%r did not match %r)r\)rrrXrY)rNr^rUr>rrr�assertMultilineMatches sz$DebuggerTests.assertMultilineMatchescCstd�S)Nz
gdb_sample.py)r)rNrrr�get_sample_script%szDebuggerTests.get_sample_script)NF)
�__name__�
__module__�__qualname__�__doc__rWrVr[r_r`rarrrrrA�sh
"rAc@s�eZdZdd�Zd<dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd=d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�ZdS)>�PrettyPrintTestscCs|�d�}|�t|k�dS)Nzid(42))rVr]rW)rNrZrrr�test_getting_backtrace)s
z'PrettyPrintTests.test_getting_backtraceNcCsB|�dt|�d�\}}|s&t|�}|�||d|||f�dS)Nzid(�)z1%r did not equal expected %r; full output was:
%s)r[�ascii�repr�assertEqual)rN�valZexp_repr�gdb_reprrZrrr�
assertGdbRepr-szPrettyPrintTests.assertGdbReprcCs6|�d�|�d�|�d�|�d�|�d�dS)z0Verify the pretty-printing of various int values�*ri����lJ)�l�����I�5N)rn)rNrrr�test_int7s




zPrettyPrintTests.test_intcCs"|�d�|�d�|�d�dS)z2Verify the pretty-printing of True, False and NoneTFN)rn)rNrrr�test_singletons?s

z PrettyPrintTests.test_singletonscCs0|�i�|�ddid�|�ddd�d�dS)z*Verify the pretty-printing of dictionaries�foo�barz{'foo': 'bar'}ro)rrZdouglasz{'foo': 'bar', 'douglas': 42}N)rn)rNrrr�
test_dictsEs
zPrettyPrintTests.test_dictscCs |�g�|�ttd���dS)z#Verify the pretty-printing of lists�N)rn�list�range)rNrrr�
test_listsLs
zPrettyPrintTests.test_listscCsR|�d�|�d�|�d�|�d�|�d�|�tdd�td�D���d	S)
z#Verify the pretty-printing of bytes�s(And now for something hopefully the sames7string with embedded NUL here  and then some more texts7this is a tab:	 this is a slash-N:
 this is a slash-R:
s!this is byte 255:� and byte 128:�cSsg|]}|�qSrr)r%�brrrrE]sz/PrettyPrintTests.test_bytes.<locals>.<listcomp>�N)rn�bytesrw)rNrrr�
test_bytesQs




zPrettyPrintTests.test_bytescsxtdd�\}}|���|s�s,td|������fdd�}��d���d���d�|d	�|d
�|td��dS)
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: csFy|���d}Wn$tk
r6��|t|��YnX��|�dS)NT)�encode�UnicodeEncodeErrorrnri)�textZ	printable)�encodingrNrr�
check_repros
z1PrettyPrintTests.test_strings.<locals>.check_repr�z(And now for something hopefully the samez7string with embedded NUL here  and then some more textu☠u文字化けi!�N)r<�rstrip�RuntimeErrorrn�chr)rNr:r;r�r)r�rNr�test_strings_s
	


zPrettyPrintTests.test_stringscCs(|�t�d�|�dd�|�d�dS)z$Verify the pretty-printing of tuplesz())r
z(1,))rrrsZbazN)rn�tuple)rNrrr�test_tuples�szPrettyPrintTests.test_tuplescCs�ttfdkr|�d�|�t�d�|�tdg�d�tjjsh|�tddg�d�|�tdd	d
g�d�|�d�\}}|�	|d
�dS)z"Verify the pretty-printing of sets)r!�z.pretty-printing of sets needs gdb 7.3 or laterzset()�az{'a'}rzz
{'a', 'b'}r-ru�z	{4, 5, 6}z&s = set(['a','b'])
s.remove('a')
id(s)z{'b'}N)
r5r6�skipTestrn�setrIr+�ignore_environmentr[rk)rNrmrZrrr�	test_sets�s

zPrettyPrintTests.test_setscCslttfdkr|�d�|�t�d�|�tdg�d�tjjsh|�tddg�d�|�tdd	d
g�d�dS)
z(Verify the pretty-printing of frozensets)r!r�z4pretty-printing of frozensets needs gdb 7.3 or laterzfrozenset()r�zfrozenset({'a'})rzzfrozenset({'a', 'b'})r-rur�zfrozenset({4, 5, 6})N)r5r6r�rn�	frozensetrIr+r�)rNrrr�test_frozensets�s
z PrettyPrintTests.test_frozensetscCs8|�d�\}}|�|d�|�d�\}}|�|d�dS)NzR
try:
    raise RuntimeError("I am an error")
except RuntimeError as e:
    id(e)
zRuntimeError('I am an error',)z=
try:
    a = 1 / 0
except ZeroDivisionError as e:
    id(e)
z&ZeroDivisionError('division by zero',))r[rk)rNrmrZrrr�test_exceptions�s

z PrettyPrintTests.test_exceptionscCs0|�d�\}}t�d|�}|j|d|d�dS)z7Verify the pretty-printing of new-style class instancesz8
class Foo:
    pass
foo = Foo()
foo.an_int = 42
id(foo)z*<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>z'Unexpected new-style class rendering %r)r\N)r[rrr])rNrmrZr>rrr�test_modern_class�s

z"PrettyPrintTests.test_modern_classcCs0|�d�\}}t�d|�}|j|d|d�dS)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)z*<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>z'Unexpected new-style class rendering %r)r\N)r[rrr])rNrmrZr>rrr�test_subclassing_list�s

z&PrettyPrintTests.test_subclassing_listcCs0|�d�\}}t�d|�}|j|d|d�dS)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)z*<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>z'Unexpected new-style class rendering %r)r\N)r[rrr])rNrmrZr>rrr�test_subclassing_tuple�s

z'PrettyPrintTests.test_subclassing_tuplec	Cs`|r|dg}ndg}|j||d�\}}|r6||kr6dSd}t�||�}|s\|�d||f�dS)z�Run Python under gdb, corrupting variables in the inferior process
        immediately before taking a backtrace.

        Verify that the variable's representation is the expected failsafe
        representationrD)rRNz<.* at remote 0x-?[0-9a-f]+>z$Unexpected gdb representation: %r
%s)r[rrrY)	rNrOZ
corruption�expreprrRrmrZrUr>rrr�
assertSane�s
zPrettyPrintTests.assertSanecCs&|jdddgd�\}}|�|d�dS)z2Ensure that a NULL PyObject* is handled gracefullyzid(42)zset variable v=0rD)rRZ0x0N)r[rk)rNrmrZrrr�
test_NULL_ptrszPrettyPrintTests.test_NULL_ptrcCs|�dd�dS)z?Ensure that a PyObject* with NULL ob_type is handled gracefullyzid(42)zset v->ob_type=0N)r�)rNrrr�test_NULL_ob_typesz"PrettyPrintTests.test_NULL_ob_typecCs|jdddd�dS)zDEnsure that a PyObject* with a corrupt ob_type is handled gracefullyzid(42)zset v->ob_type=0xDEADBEEF�42)r�N)r�)rNrrr�test_corrupt_ob_typesz%PrettyPrintTests.test_corrupt_ob_typecCs|jdddd�dS)zDEnsure that a PyObject* with a type with corrupt tp_flags is handledzid(42)zset v->ob_type->tp_flags=0x0r�)r�N)r�)rNrrr�test_corrupt_tp_flags sz&PrettyPrintTests.test_corrupt_tp_flagscCs|jdddd�dS)zCEnsure that a PyObject* with a type with corrupt tp_name is handledzid(42)z"set v->ob_type->tp_name=0xDEADBEEFr�)r�N)r�)rNrrr�test_corrupt_tp_name&sz%PrettyPrintTests.test_corrupt_tp_namecCsFtjjr|�d�|jddd�\}}t�d|�}|j|d|d�dS)	zAEnsure that the new-style class _Helper in site.py can be handledz(need site module, but -S option was usedzid(__builtins__.help)T)rSz!<_Helper at remote 0x-?[0-9a-f]+>zUnexpected rendering %r)r\N)rIr+�no_siter�r[rrr])rNrmrZr>rrr�test_builtins_help,s
z#PrettyPrintTests.test_builtins_helpcCs8|�d�\}}|�|d�|�d�\}}|�|d�dS)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, [[...]]]N)r[rk)rNrmrZrrr�test_selfreferential_list:sz*PrettyPrintTests.test_selfreferential_listcCs|�d�\}}|�|d�dS)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': {...}}}N)r[rk)rNrmrZrrr�test_selfreferential_dictEsz*PrettyPrintTests.test_selfreferential_dictcCs.|�d�\}}|�t�d|�d||f�dS)Nz:
class Foo:
    pass
foo = Foo()
foo.an_attr = foo
id(foo)z1<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>z$Unexpected gdb representation: %r
%s)r[r]rr)rNrmrZrrr�'test_selfreferential_old_style_instanceMs

z8PrettyPrintTests.test_selfreferential_old_style_instancecCsX|�d�\}}|�t�d|�d||f�|�d�\}}|�t�d|�d||f�dS)NzB
class Foo(object):
    pass
foo = Foo()
foo.an_attr = foo
id(foo)z1<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>z$Unexpected gdb representation: %r
%szR
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]rr)rNrmrZrrr�'test_selfreferential_new_style_instanceZs



z8PrettyPrintTests.test_selfreferential_new_style_instancecCs6|�d�\}}|�|d�|�t|�dtd��dS)z)Verify that very long output is truncatedzid(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)iz...(truncated)N)r[rk�len)rNrmrZrrr�test_truncationus

z PrettyPrintTests.test_truncationcCs.|�d�\}}|�t�d|�d||f�dS)Nz$import sys; id(sys.stdout.readlines)zO<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>z$Unexpected gdb representation: %r
%s)r[r]rr)rNrmrZrrr�test_builtin_method�s

z$PrettyPrintTests.test_builtin_methodcCs6|jdddgd�}|�t�d|tj�d||f�dS)Nz:
def foo(a, b, c):
    pass

foo(3, 4, 5)
id(foo.__code__)r@z:print (PyFrameObject*)(((PyCodeObject*)v)->co_zombieframe))rQrRzM.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*z$Unexpected gdb representation: %r
%s)rVr]rrrX)rNrZrrr�test_frames�s

zPrettyPrintTests.test_frames)N)N) rbrcrdrgrnrprqrtrxr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrf(s:

-


rfz&Python was compiled with optimizationsc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�PyListTestscCs|�||�dS)N)r_)rNZexpectedr^rrr�
assertListing�szPyListTests.assertListingcCs$|j|��dgd�}|�d|�dS)z'Verify that the "py-list" command workszpy-list)rPrRz�   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)rVrar�)rN�btrrr�test_basic_command�s

zPyListTests.test_basic_commandcCs$|j|��dgd�}|�d|�dS)z7Verify the "py-list" command with one absolute argumentz	py-list 9)rPrRzI   9    def baz(*args):
 >10        id(42)
  11    
  12    foo(1, 2, 3)
N)rVrar�)rNr�rrr�test_one_abs_arg�s

zPyListTests.test_one_abs_argcCs$|j|��dgd�}|�d|�dS)z8Verify the "py-list" command with two absolute argumentszpy-list 1,3)rPrRzR   1    # Sample script for use by test_gdb.py
   2    
   3    def foo(a, b, c):
N)rVrar�)rNr�rrr�test_two_abs_args�s

zPyListTests.test_two_abs_argsN)rbrcrdr�r�r�r�rrrrr��sr�c@sxeZdZe�ed�e�e�d�dd���Ze�ed�dd��Z	e�ed�dd��Z
e�ed�e�e�d�d	d
���ZdS)�StackNavigationTestsz$test requires py-up/py-down commandsz&Python was compiled with optimizationscCs&|j|��ddgd�}|�|d�dS)z%Verify that the "py-up" command workszpy-up)rPrRzp^.*
#[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\)
$N)rVrar`)rNr�rrr�test_pyup_command�s
z&StackNavigationTests.test_pyup_commandcCs$|j|��dgd�}|�|d�dS)z7Verify handling of "py-down" at the bottom of the stackzpy-down)rPrRz$Unable to find a newer python frame
N)rVrar_)rNr�rrr�test_down_at_bottom�s

z(StackNavigationTests.test_down_at_bottomcCs(|j|��dgdd�}|�|d�dS)z2Verify handling of "py-up" at the top of the stackzpy-upru)rPrRz%Unable to find an older python frame
N)rVrar_)rNr�rrr�test_up_at_top�s
z#StackNavigationTests.test_up_at_topcCs(|j|��dddgd�}|�|d�dS)z$Verify "py-up" followed by "py-down"zpy-upzpy-down)rPrRz�^.*
#[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 10, in baz \(args=\(1, 2, 3\)\)
    id\(42\)
$N)rVrar`)rNr�rrr�test_up_then_down�s
z&StackNavigationTests.test_up_then_downN)rbrcrdr�
skipUnless�HAS_PYUP_PYDOWN�skipIfrr�r�r�r�rrrrr��s

r�c@s�eZdZe�e�d�dd��Ze�e�d�dd��Zdd�Ze�e�d�dd	��Z	e�e�d�d
d��Z
e�e�d�dd
��ZdS)�	PyBtTestsz&Python was compiled with optimizationscCs$|j|��dgd�}|�|d�dS)z%Verify that the "py-bt" command workszpy-bt)rPrRaF^.*
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, b, c\)
  File ".*gdb_sample.py", line 12, in <module>
    foo\(1, 2, 3\)
N)rVrar`)rNr�rrr�test_bt�s

zPyBtTests.test_btcCs$|j|��dgd�}|�|d�dS)z*Verify that the "py-bt-full" command worksz
py-bt-full)rPrRa>^.*
#[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, b, c\)
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 12, in <module> \(\)
    foo\(1, 2, 3\)
N)rVrar`)rNr�rrr�test_bt_fulls

zPyBtTests.test_bt_fullcCs@d}|j|dgd�}|�d|�|j|dgd�}|�d|�dS)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)

zthread apply all py-bt)rRzWaiting for the GILzthread apply all py-bt-fullN)rV�assertIn)rNrrZrrr�test_threads#s

zPyBtTests.test_threadscCsHd}|j|dddgd�}|�d|�|j|dddgd�}|�d|�dS)	z?Verify that "py-bt" indicates if a thread is garbage-collectingzRfrom gc import collect
id(42)
def foo():
    collect()
def bar():
    foo()
bar()
zbreak update_refs�continuezpy-bt)rRzGarbage-collectingz
py-bt-fullN)rVr�)rNrrZrrr�test_gcCszPyBtTests.test_gccCsFd}|j|dddgd�}|�d|�|j|ddgd�}|�d|�d	S)
zAVerify that "py-bt" displays invocations of PyCFunction instanceszLfrom time import gmtime
def foo():
    gmtime(1)
def bar():
    foo()
bar()
Ztime_gmtimer�zpy-bt)rQrRz<built-in method gmtimez
py-bt-fullz#2 <built-in method gmtimeN)rVr�)rNrrZrrr�test_pycfunction]s	
zPyBtTests.test_pycfunctioncCsHt�d�}ddg}tr |�d�|�d�|j||d�}|�|d�dS)Nz�
            class MyList(list):
                def __init__(self):
                    super().__init__()   # wrapper_call()

            id("first break point")
            l = MyList()
        zbreak wrapper_callr�rCzpy-bt)rRz1<method-wrapper u?'__init__' of MyList object at )�textwrap�dedentrH�appendrVZassertRegex)rNrrRrZrrr�test_wrapper_callzs

zPyBtTests.test_wrapper_callN)rbrcrdrr�rr�r�r�r�r�r�rrrrr��s r�c@speZdZe�e�d�dd��Ze�e�d�e�ed�dd���Z	e�e�d�dd��Z
e�e�d�d	d
��ZdS)�PyPrintTestsz&Python was compiled with optimizationscCs&|j|��ddgd�}|�|d�dS)z(Verify that the "py-print" command workszpy-upz
py-print args)rPrRz".*\nlocal 'args' = \(1, 2, 3\)\n.*N)rVrar`)rNr�rrrr��s
zPyPrintTests.test_basic_commandz$test requires py-up/py-down commandscCs,|j|��dddddgd�}|�|d�dS)Nzpy-upz
py-print cz
py-print bz
py-print a)rPrRz3.*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*)rVrar`)rNr�rrr�test_print_after_up�s
z PyPrintTests.test_print_after_upcCs&|j|��ddgd�}|�|d�dS)Nzpy-upzpy-print __name__)rPrRz&.*\nglobal '__name__' = '__main__'\n.*)rVrar`)rNr�rrr�test_printing_global�s
z!PyPrintTests.test_printing_globalcCs&|j|��ddgd�}|�|d�dS)Nzpy-upzpy-print len)rPrRzV.*\nbuiltin 'len' = <built-in method len of module object at remote 0x-?[0-9a-f]+>\n.*)rVrar`)rNr�rrr�test_printing_builtin�s
z"PyPrintTests.test_printing_builtinN)rbrcrdrr�rr�r�r�r�r�r�rrrrr��sr�c@sDeZdZe�e�d�dd��Ze�ed�e�e�d�dd���Z	dS)�
PyLocalsTestsz&Python was compiled with optimizationscCs&|j|��ddgd�}|�|d�dS)Nzpy-upz	py-locals)rPrRz.*\nargs = \(1, 2, 3\)\n.*)rVrar`)rNr�rrrr��s
z PyLocalsTests.test_basic_commandz$test requires py-up/py-down commandscCs(|j|��dddgd�}|�|d�dS)Nzpy-upz	py-locals)rPrRz.*\na = 1\nb = 2\nc = 3\n.*)rVrar`)rNr�rrr�test_locals_after_up�s
z"PyLocalsTests.test_locals_after_upN)
rbrcrdrr�rr�r�r�r�rrrrr��s

r�cCsJtjr4tdttf�xt��D]}td|�q Wttt	t
ttt
�dS)NzGDB version %s.%s:z    )r�verboserMr5r6�gdb_versionrLrrfr�r�r�r�r�)rTrrr�	test_main�sr��__main__)3�localer1�platformrrrIr(r�rZtestrZtest.supportrrrr r�r5r6rZis_python_buildZpython_compiler�pathr�dirnamerJr7rFr,rHr<Z
gdbpy_versionr=Zgdbpy_errorsr\r�r?r�rWr�ZPGOZTestCaserArfr�r�r�r�r�r�rbrrrr�<module>sl





	
 (-#