Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_gdb.cpython-311.opt-2.pyc
�

�Ke������ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZd�Z
e
��\ZZZedkrejde�de�de�����ej��sejd	���d
ej��vrejdkrejd���ejd
��pdejd��pdvrejd���ej�ej�ej��d��ZdZd�Ze��Zd�Zed��\ZZesejd���devrejd���edej��\ZZ de vr'dZ!eje!e �"��z���d�Z#e#��Z$dZ%ej&e	j'd��Gd �d!ej(����Z)Gd"�d#e)��Z*ej&e��d$��Gd%�d&e)����Z+d'Z,Gd(�d)e)��Z-Gd*�d+e)��Z.Gd,�d-e)��Z/Gd.�d/e)��Z0d0�Z1e2d1krej3��dSdS)2�N)�support)�findfile�python_is_optimizedc
�\�	gd�}tj|tjtjd���}|5|���\}}ddd��n#1swxYwY|jr3tdd�|���d|j�d|�d|�����n"#t$rtj	d	���wxYwtjd
|��}|�td|z���|t|�
d����t|�
d
����fS)N)�gdb�-nxz	--versionT)�stdout�stderr�universal_newlineszCommand � z failed with exit code z	: stdout=z stderr=zCouldn't find gdb on the pathz ^(?:GNU|HP) 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
�matchs     �7/usr/local/apps/python3/lib/python3.11/test/test_gdb.py�get_gdb_versionr"s���A�)�)�)�����'1��'1��37�9�9�9���	1�	1�"�.�.�0�0�O�G�V�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1����	1�	1�	1�	1��?�	E��D�s�x�x��}�}�D�D�.2�o�D�D�&-�D�D�9?�D�D�E�E�
E�	E���A�A�A��� ?�@�@�@�A����
�I�9�7�C�C�E��}��9�G�C�D�D�D��S����Q���(�(�#�e�k�k�!�n�n�*=�*=�>�>s.�2B�A�B�A�B�A� =B�B=�z=gdb versions before 7.0 didn't support python embedding. Saw �.z:
z3test_gdb only works on source builds at the moment.�Clang�darwinzDtest_gdb doesn't work correctly when python is built with LLVM clang�PGO_PROF_USE_FLAG�xxx�PY_CORE_CFLAGS�z&test_gdb is not reliable on PGO buildsz
python-gdb.py�123c��tjd��}|sdS|���}d|votd�|D����S)N�CFLAGSFz-mcetc3�lK�|]/}|�d��o|�d��V��0dS)z-fcf-protection)z=nonez=returnN)�
startswith�endswith)�.0�flags  r!�	<genexpr>z!cet_protection.<locals>.<genexpr>Qs\����'�'���_�_�%6�7�7�A�!�]�]�+?�@�@�@�'�'�'�'�'�'�)�	sysconfig�get_config_var�split�any)�cflags�flagss  r!�cet_protectionr;Isi��
�
%�h�
/�
/�F����u��L�L�N�N�E���
�
'��'�'� %�'�'�'�'�'�(r4c���	|r4tj���}|�|��nd}d}tt
fdkr|ddtzfz
}tj||ztj	tj	tj	|���}|5|�
��\}}ddd��n#1swxYwY|�dd��|�dd��fS)N)rz--batchr�r#�z-iexzadd-auto-load-safe-path )�stdinr	r
�envzutf-8�replace)�os�environ�copy�update�gdb_major_version�gdb_minor_version�checkout_hook_pathrrrr�decode)�args�env_varsr@�base_cmdr�out�errs       r!�run_gdbrOYs4������j�o�o�����
�
�8�������)�H��,�-��7�7��V�7�:L�L�M�M����H�t�O�#-�/�#-�?�#-�?� #�
%�%�%�D�
�&�&��#�#�%�%���S�&�&�&�&�&�&�&�&�&�&�&����&�&�&�&��:�:�g�y�)�)�3�:�:�g�y�+I�+I�I�Is�B=�=C�Cz9--eval-command=python import sys; print(sys.version_info)z*gdb not built with embedded python supportzmajor=2zgdb built with Python 2�--argszauto-loading has been declinedz3gdb security settings prevent use of custom hooks: c���td��\}}tjd|��}|stjd���|�d���d��}d|vS)Nz+--eval-command=python print(dir(gdb.Frame))z.*\[(.*)\].*z1Unable to parse output from gdb.Frame.select testr
z, z'select')rOrr rrrr7)r	�_�m�
gdb_frame_dirs    r!�gdb_has_frame_selectrU�sh���E�F�F�I�F�A�
���&�)�)�A��U��� S�T�T�T��G�G�A�J�J�$�$�T�*�*�M���&�&r4�
builtin_idznot useful for PGOc�B�eZdZ	ddedddfd�Z		dd�Zd�Zd�Zd�ZdS)	�
DebuggerTestsNFc�:�	dd|zddg}ttfdkr|dgz
}|rtr|dgz
}||z
}n|dgz
}d	�|D��}|d
tjgz
}|�t
j����|s|dgz
}|r|d|gz
}n|r||gz
}t|d
ti�\}	}
|s2|
�
��D]}t|tj����d|
vrtjd���dD]}||	vrtj|�d�����|	S)Nzset breakpoint pending yeszbreak %szset print address off�runr=zset print entry-values no�next�	backtracec��g|]}d|z��S)z--eval-command=%s�)r1rs  r!�
<listcomp>z1DebuggerTests.get_stack_trace.<locals>.<listcomp>�s��>�>�>�c�#�c�)�>�>�>r4rPz-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)rFrG�CET_PROTECTION�sys�
executable�extendr�_args_from_interpreter_flagsrOr`�
splitlines�printr
rr)
�self�source�script�
breakpoint�cmds_after_breakpoint�import_site�
ignore_stderr�commandsrJrMrN�line�patterns
             r!�get_stack_tracezDebuggerTests.get_stack_trace�s���
	�.1���+�,��
��*
�0�1�V�;�;��4�5�5�H� �		&��
%�
�V�H�$���-�-�H�H���
�%�H�
?�>�X�>�>�>������!�	!�����J�;�=�=�>�>�>��	��T�F�N�D��	��T�6�N�"�D�D�
�	��V�H��D��D�@��@�@���S��	-����(�(�
-�
-���d���,�,�,�,�,��S� � ��#�%3�4�4�
4�
�	L�	L�G��#�~�~��'�7�(J�(J�(J�K�K�K���
r4c���|pdg}|�|t||���}tjd|tj��}|s|�d|�d|����|�d��|fS)Nzbacktrace 1)rlrmrnzS#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)?\)\s+at\s+\S*[A-Za-z]+/[A-Za-z0-9_-]+\.czUnexpected gdb output: �
r
)rs�
BREAKPOINT_FNrr�DOTALL�failr)rirjrmrn�
gdb_outputrSs      r!�get_gdb_reprzDebuggerTests.get_gdb_reprs��� !6� H�-����)�)�&�]�@U�6A�*�C�C�
�
�I�
6�
��	�
#�
#���	R��I�I�I����Z�Z�P�Q�Q�Q��w�w�q�z�z�:�%�%r4c�f�	|�|�|��|�d|�����dS)Nz did not end with ��msg)�
assertTruer0)ri�actual�exp_ends   r!�assertEndsWithzDebuggerTests.assertEndsWith$sK��G��������0�0�8>�����H�	�	J�	J�	J�	J�	Jr4c��tj||tj��}|s|�|�d|�����dSdS)Nz did not match r|)rr rwrx)rirrrrSs    r!�assertMultilineMatchesz$DebuggerTests.assertMultilineMatches)sQ���H�W�f�b�i�0�0���	E��I�I�6�6�6�7�7�C�I�D�D�D�D�D�	E�	Er4c� �td��S)Nz
gdb_sample.py)r�ris r!�get_sample_scriptzDebuggerTests.get_sample_script.s����(�(�(r4)NF)	�__name__�
__module__�__qualname__rvrsrzr�r�r�r^r4r!rXrX�s�������3�%)�$�#0�.2�$)�&+�	j�j�j�j�Z,0�!&�"&�"&�"&�"&�HJ�J�J�
E�E�E�
)�)�)�)�)r4rXc��eZdZd�Zdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS) �PrettyPrintTestsc�h�|�d��}|�t|v��dS)N�id(42))rsr~rv�rirys  r!�test_getting_backtracez'PrettyPrintTests.test_getting_backtrace2s2���)�)�(�3�3�
����
��3�4�4�4�4�4r4Nc	��|�dt|��zdz��\}}|st|��}|�|||�d|�d|����dS)Nzid(�)z did not equal expected z; full output was:
)rz�ascii�repr�assertEqual)ri�val�exp_repr�gdb_reprrys     r!�
assertGdbReprzPrettyPrintTests.assertGdbRepr6s{�� $�0�0���s���1C�c�1I�J�J���*��	!��C�y�y�H�����8�%�X�X�x�x�x���=�	?�	?�	?�	?�	?r4c���	|�d��|�d��|�d��|�d��|�d��dS)N�*ri����lJ)�l�����I�5�r�r�s r!�test_intzPrettyPrintTests.test_int@sp��:����2�������1�������2�������=�)�)�)����,�-�-�-�-�-r4c��	|�d��|�d��|�d��dS)NTFr�r�s r!�test_singletonsz PrettyPrintTests.test_singletonsHsG��<����4� � � ����5�!�!�!����4� � � � � r4c��	|�i��|�ddid��|�ddd�d��dS)N�foo�barz{'foo': 'bar'}r�)r��douglasz{'foo': 'bar', 'douglas': 42}r�r�s r!�
test_dictszPrettyPrintTests.test_dictsNsY��4����2�������E�5�>�+;�<�<�<����5�R�8�8�:Y�Z�Z�Z�Z�Zr4c��	|�g��|�ttd������dS)N�)r��list�ranger�s r!�
test_listszPrettyPrintTests.test_listsUs?��-����2�������4��a���>�>�*�*�*�*�*r4c�L�	|�d��|�d��|�d��|�d��|�d��|�td�td��D������dS)Nr4s(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:�c��g|]}|��Sr^r^)r1�bs  r!r_z/PrettyPrintTests.test_bytes.<locals>.<listcomp>fs��!8�!8�!8��!�!8�!8�!8r4�)r��bytesr�r�s r!�
test_byteszPrettyPrintTests.test_bytesZs���-����3�������F�G�G�G����V�W�W�W����4�	�	�	�
	
���E�F�F�F����5�!8�!8�U�3�Z�Z�!8�!8�!8�9�9�:�:�:�:�:r4c�l���	tdd��\}}|����|s�std|�������fd�}��d����d����d��|d��|d	��|t	d
����dS)Nz--eval-commandz:python import locale; print(locale.getpreferredencoding())zFunable to determine the preferred encoding of embedded Python in GDB: c����	|������|��dS#t$r'��|t|����YdSwxYw�N)�encoder��UnicodeEncodeErrorr�)�text�encodingris ��r!�
check_reprz1PrettyPrintTests.test_strings.<locals>.check_reprxsx���
)����H�%�%�%��"�"�4�(�(�(�(�(��&�
6�
6�
6��"�"�4��t���5�5�5�5�5�5�
6���s�/�-A �A r*z(And now for something hopefully the samez7string with embedded NUL here  and then some more textu☠u文字化けi!�)rO�rstrip�RuntimeErrorr��chr)rirMrNr�r�s`   @r!�test_stringszPrettyPrintTests.test_stringshs����7�
��H�J�J���S��:�:�<�<���	5�h�	5��4�.1�4�4�5�5�
5�	)�	)�	)�	)�	)�	)�	
���2�������E�F�F�F����U�V�V�V�	�
�8����
	�
�-�.�.�.�	�
�3�w�<�<� � � � � r4c��	|�t��d��|�dd��|�d��dS)Nz())r
z(1,))r�r��baz)r��tupler�s r!�test_tupleszPrettyPrintTests.test_tuples�sP��.����5�7�7�D�)�)�)����4��(�(�(����0�1�1�1�1�1r4c���	ttfdkr|�d��|�t	��d��|�t	dg��d��t
jjsJ|�t	ddg��d��|�t	gd���d	��|�d
��\}}|�	|d��dS)N�r#�z.pretty-printing of sets needs gdb 7.3 or laterzset()�az{'a'}r�z
{'a', 'b'}�r>r��z	{4, 5, 6}z&s = set(['a','b'])
s.remove('a')
id(s)z{'b'})
rFrG�skipTestr��setrcr:�ignore_environmentrzr��rir�rys   r!�	test_setszPrettyPrintTests.test_sets�s���,��0�1�F�:�:��M�M�J�K�K�K����3�5�5�'�*�*�*����3��u�:�:�w�/�/�/��y�+�	<����s�C��:����=�=�=����s�9�9�9�~�~�{�;�;�;� $�0�0�2	� 
� 
���*�	
����7�+�+�+�+�+r4c��	ttfdkr|�d��|�t	��d��|�t	dg��d��t
jjsL|�t	ddg��d��|�t	gd���d	��dSdS)
Nr�z4pretty-printing of frozensets needs gdb 7.3 or laterzfrozenset()r�zfrozenset({'a'})r�zfrozenset({'a', 'b'})r�zfrozenset({4, 5, 6}))rFrGr�r��	frozensetrcr:r�r�s r!�test_frozensetsz PrettyPrintTests.test_frozensets�s���2��0�1�F�:�:��M�M�P�Q�Q�Q����9�;�;�
�6�6�6����9�c�U�+�+�-?�@�@�@��y�+�	M����y�#�s��4�4�6M�N�N�N����y����3�3�5K�L�L�L�L�L�	M�	Mr4c��|�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',)�rzr�r�s   r!�test_exceptionsz PrettyPrintTests.test_exceptions�s���#�0�0�2� � ���*�	
����9�	;�	;�	;�
 $�0�0�2� � ���*�	
����A�	C�	C�	C�	C�	Cr4c��	|�d��\}}tjd|��}|�|d|z���dS)Nz8
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 %rr|�rzrr r~�rir�ryrSs    r!�test_modern_classz"PrettyPrintTests.test_modern_class�sl��A�#�0�0�2� � ���*�
�H�B�H�M�M������E��P�	�	R�	R�	R�	R�	Rr4c��	|�d��\}}tjd|��}|�|d|z���dS)NzO
class Foo(list):
    pass
foo = Foo()
foo += [1, 2, 3]
foo.an_int = 42
id(foo)r�r�r|r�r�s    r!�test_subclassing_listz&PrettyPrintTests.test_subclassing_list�sl��F�#�0�0�2� � ���*�
�H�B�H�M�M������E��P�	�	R�	R�	R�	R�	Rr4c��	|�d��\}}tjd|��}|�|d|z���dS)NzH
class Foo(tuple):
    pass
foo = Foo((1, 2, 3))
foo.an_int = 42
id(foo)r�r�r|r�r�s    r!�test_subclassing_tuplez'PrettyPrintTests.test_subclassing_tuple�sn��G� $�0�0�2� � ���*�
�H�B�H�M�M������E��P�	�	R�	R�	R�	R�	Rr4c���	|r|dg}ndg}|�||���\}}|r||krdSd}tj||��}|s|�d|�d|����dSdS)Nr\�rmz<.* at remote 0x-?[0-9a-f]+>�Unexpected gdb representation: ru)rzrr rx)	rirj�
corruption�expreprrmr�ryrrrSs	         r!�
assertSanezPrettyPrintTests.assertSane�s���	�
�	0�#-�{�";�!�!�#.�-�!�
���f�4I�
�
K�
K�	��*��	��7�"�"���1���H�W�h�'�'���	2��I�I�I�#�8�8�Z�Z�1�
2�
2�
2�
2�
2�	2�	2r4c�l�	|�dddg���\}}|�|d��dS)Nr�zset variable v=0r\r��0x0r�r�s   r!�
test_NULL_ptrzPrettyPrintTests.test_NULL_ptrsT��<����h�5G�5@�5B�
�
C�
C�	��*�	
����5�)�)�)�)�)r4c�4�	|�dd��dS)Nr�zset v->ob_type=0�r�r�s r!�test_NULL_ob_typez"PrettyPrintTests.test_NULL_ob_types*��I�����*�	,�	,�	,�	,�	,r4c�8�	|�ddd���dS)Nr�zset v->ob_type=0xDEADBEEF�42�r�r�r�s r!�test_corrupt_ob_typez%PrettyPrintTests.test_corrupt_ob_type"s2��N�����3� $�	�	&�	&�	&�	&�	&r4c�8�	|�ddd���dS)Nr�zset v->ob_type->tp_flags=0x0r�r�r�r�s r!�test_corrupt_tp_flagsz&PrettyPrintTests.test_corrupt_tp_flags(s2��N�����6� $�	�	&�	&�	&�	&�	&r4c�8�	|�ddd���dS)Nr�z"set v->ob_type->tp_name=0xDEADBEEFr�r�r�r�s r!�test_corrupt_tp_namez%PrettyPrintTests.test_corrupt_tp_name.s2��M�����<� $�	�	&�	&�	&�	&�	&r4c���	tjjr|�d��|�dd���\}}tjd|��}|�|d|z���dS)Nz(need site module, but -S option was usedzid(__builtins__.help)T)rnz%<_Helper\(\) at remote 0x-?[0-9a-f]+>zUnexpected rendering %rr|)rcr:�no_siter�rzrr r~r�s    r!�test_builtins_helpz#PrettyPrintTests.test_builtins_help4s���K��9��	F��M�M�D�E�E�E� $�0�0�1H�VZ�0�[�[���*��H�=�x�H�H������5��@�	�	B�	B�	B�	B�	Br4c��	|�d��\}}|�|d��|�d��\}}|�|d��dS)Nz#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, [[...]]]r�r�s   r!�test_selfreferential_listz*PrettyPrintTests.test_selfreferential_listBsu��	"�
���C�D�D�	��*�����#5�6�6�6�
���M�N�N�	��*�����#7�8�8�8�8�8r4c�d�	|�d��\}}|�|d��dS)Nz-a = {} ; b = {'bar':a} ; a['foo'] = b ; id(a)z{'foo': {'bar': {...}}}r�r�s   r!�test_selfreferential_dictz*PrettyPrintTests.test_selfreferential_dictMsC��	"�
���M�N�N�	��*�	
����#<�=�=�=�=�=r4c��|�d��\}}|�tjd|��d|�d|����dS)Nz:
class Foo:
    pass
foo = Foo()
foo.an_attr = foo
id(foo)�1<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>r�ru�rzr~rr r�s   r!�'test_selfreferential_old_style_instancez8PrettyPrintTests.test_selfreferential_old_style_instanceUsp������
�
�	��*�	
�����!U�!)�+�+�+�&�X�X�z�z�3�	4�	4�	4�	4�	4r4c�"�|�d��\}}|�tjd|��d|�d|����|�d��\}}|�tjd|��d|�d|����dS)NzB
class Foo(object):
    pass
foo = Foo()
foo.an_attr = foo
id(foo)r�r�ruzR
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_instancebs�������
�
�	��*�	
�����!U�!)�+�+�+�&�X�X�z�z�3�	4�	4�	4�
���	�
�
�	��*�	
�����!~�!)�+�+�+�&�X�X�z�z�3�	4�	4�	4�	4�	4r4c���	|�d��\}}|�|d��|�t|��dtd��z��dS)Nzid(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))rzr��lenr�s   r!�test_truncationz PrettyPrintTests.test_truncation}sz��3�#�0�0�1H�I�I���*�����7�	8�	8�	8�,	
����X�����$4� 5� 5�5�	7�	7�	7�	7�	7r4c��|�d��\}}|�tjd|��d|�d|����dS)Nz$import sys; id(sys.stdout.readlines)zO<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>r�rur�r�s   r!�test_builtin_methodz$PrettyPrintTests.test_builtin_method�sf��#�0�0�1W�X�X���*������!s�!)�+�+�+�&�X�X�z�z�3�	4�	4�	4�	4�	4r4c��|�dddg���}|�tjd|tj��d|�d|����dS)NzQ
import sys
def foo(a, b, c):
    return sys._getframe(0)

f = foo(3, 4, 5)
id(f)rVzprint (PyFrameObject*)v)rlrmzK.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 4, in foo \(a=3.*r�ru)rsr~rr rwr�s  r!�test_frameszPrettyPrintTests.test_frames�s����)�)�+	�6B�AZ�@[�*�	,�	,�
�	
�����!o�!+�!#��,�,�,�DN�:�:�z�z�Z�	\�	\�	\�	\�	\r4r�) 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�r�r�r�r�rr^r4r!r�r�1s�������5�5�5�?�?�?�?�.�.�.�!�!�!�[�[�[�+�+�+�
;�;�;�*!�*!�*!�X2�2�2�,�,�,�$	M�	M�	M�C�C�C�,
R�
R�
R�R�R�R�
R�
R�
R�2�2�2�2�:*�*�*�,�,�,�
&�&�&�&�&�&�&�&�&�B�B�B�	9�	9�	9�>�>�>�4�4�4�4�4�4�67�7�7�84�4�4�\�\�\�\�\r4r��&Python was compiled with optimizationsc�&�eZdZd�Zd�Zd�Zd�ZdS)�PyListTestsc�2�|�||��dSr�)r�)ri�expectedrs   r!�
assertListingzPyListTests.assertListing�s�����F�H�-�-�-�-�-r4c��	|�|���dg���}|�d|��dS)Nzpy-list�rkrmz�   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)
�rsr�r�ri�bts  r!�test_basic_commandzPyListTests.test_basic_command�sb��1�
�
!�
!��)?�)?�)A�)A�9B��"�E�E��	
���4��	�	�	�	�	r4c��	|�|���dg���}|�d|��dS)Nz	py-list 9r	zI   9    def baz(*args):
 >10        id(42)
  11    
  12    foo(1, 2, 3)
r
rs  r!�test_one_abs_argzPyListTests.test_one_abs_arg�sb��A�
�
!�
!��)?�)?�)A�)A�9D�
�"�G�G��	
���4��		�	�	�	�	r4c��	|�|���dg���}|�d|��dS)Nzpy-list 1,3r	zR   1    # Sample script for use by test_gdb.py
   2    
   3    def foo(a, b, c):
r
rs  r!�test_two_abs_argszPyListTests.test_two_abs_args�sb��B�
�
!�
!��)?�)?�)A�)A�9F��"�I�I��	
���9��	�	�	�	�	r4N)r�r�r�rr
rrr^r4r!rr�sP������.�.�.�
�
�
�	�	�	�����r4rz�

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�Z�eZdZejed��eje��d��d�����Zejed��d���Z	ejed��d���Z
ejed��eje��d��d�����ZdS)�StackNavigationTests�$test requires py-up/py-down commandsrc�p�	|�tddg���}|�|d��dS)N�py-up�rjrmz�^.*
#[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]+>
$�rs�SAMPLE_WITH_C_CALLr�rs  r!�test_pyup_commandz&StackNavigationTests.test_pyup_command�sW��	0�
�
!�
!�);�9@�'�8J�"�L�L���#�#�B�%�	�	�	�	�	r4c��	|�|���dg���}|�|d��dS)N�py-downr	z$Unable to find a newer python frame
�rsr�r�rs  r!�test_down_at_bottomz(StackNavigationTests.test_down_at_bottom�s`��A�
�
!�
!��)?�)?�)A�)A�9B��"�E�E�����B�C�	E�	E�	E�	E�	Er4c��	|�|���dgdz���}|�|d��dS)Nrr�r	z%Unable to find an older python frame
rrs  r!�test_up_at_topz#StackNavigationTests.test_up_at_topsd��<�
�
!�
!��)?�)?�)A�)A�9@�	�A�
�"�G�G�����B�D�	F�	F�	F�	F�	Fr4c�p�	|�tgd����}|�|d��dS)N)rrrra^.*
#[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\)\)
$rrs  r!�test_up_then_downz&StackNavigationTests.test_up_then_down
sX��	/�
�
!�
!�);�8U�8U�8U�"�W�W���#�#�B�%�	�	�	�	�	r4N)r�r�r�r�
skipUnless�HAS_PYUP_PYDOWN�skipIfrrrr r"r^r4r!rr�s �������X���*P�Q�Q��X�_�(�(�*�*�=�?�?���?�?�R�Q���X���*P�Q�Q�E�E�R�Q�E��X���*P�Q�Q�F�F�R�Q�F��X���*P�Q�Q��X�_�(�(�*�*�=�?�?�	�	�?�?�R�Q�	�	�	r4rc��eZdZeje��d��d���Zeje��d��d���Zeje��d��d���Zeje��d��d���Z	eje��d��d���Z
eje��d��d���ZdS)	�	PyBtTestsrc��	|�|���dg���}|�|d��dS)N�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\)
�rsr�r�rs  r!�test_btzPyBtTests.test_bts_��	0�
�
!�
!��)?�)?�)A�)A�9@�	�"�C�C���#�#�B�%�	�	�	�	�	r4c��	|�|���dg���}|�|d��dS)N�
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\)
r*rs  r!�test_bt_fullzPyBtTests.test_bt_full-s_��	5�
�
!�
!��)?�)?�)A�)A�9E��"�H�H���#�#�B�%�	�	�	�	�	r4c���	d}|�|dg���}|�d|��|�|dg���}|�d|��dS)NaN
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-btr�zWaiting for the GILzthread apply all py-bt-full�rs�assertIn�rirrys   r!�test_threadszPyBtTests.test_threads=s���	M���*�)�)�#�AY�@Z�*�\�\�
��
�
�+�Z�8�8�8��)�)�#�A^�@_�*�a�a�
��
�
�+�Z�8�8�8�8�8r4c���	d}|�|gd����}|�d|��|�|gd����}|�d|��dS)NzRfrom gc import collect
id(42)
def foo():
    collect()
def bar():
    foo()
bar()
)�break update_refs�continuer)r�zGarbage-collecting)r5r6r-r0r2s   r!�test_gczPyBtTests.test_gc_s���	J����)�)�#�@j�@j�@j�*�,�,�
�	
�
�
�*�J�7�7�7��)�)�#�@o�@o�@o�*�,�,�
�	
�
�
�*�J�7�7�7�7�7r4c���	d}dD]�\}}dD]�}|�|�d|����5tjd|�d|�d|�d���}|�||dd	gd
���}|�d|��|��|�||d
gd
���}|}|tjd|����z
}|�||��ddd��n#1swxYwY�ӌ�dS)Nz#(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)rlrmroz<built-in method r-z <built-in method )�subTest�textwrap�dedentrsr1r�escape�assertRegex)ri�expected_frame�	func_namerJ�objrry�regexs        r!�test_pycfunctionzPyBtTests.test_pycfunctionzs���	L�#�� 
�0	8�0	8�O�I�t��(
8�(
8���\�\�S�"6�"6�9�"6�"6�7�7�8�8�"�/�+�!�+�+�$-�+�+�04�+�+�+���C�"&�!5�!5��#,�/3�W�o�'+�
"6�"�"�J��M�M�"A�i�"A�"A�:�N�N�N�"&�!5�!5��#,�/;�n�'+�
"6�"�"�J�+�E��R�Y�'G�I�'G�'G�H�H�H�E��$�$�Z��7�7�7�?8�8�8�8�8�8�8�8�8�8�8����8�8�8�8��(
8�0	8�0	8s�BC�C�Cc���tjd��}ddg}tr|�d��|�d��|�||���}|�|d��dS)Nz�
            class MyList(list):
                def __init__(self):
                    super().__init__()   # wrapper_call()

            id("first break point")
            l = MyList()
        zbreak wrapper_callr6r[r)r�z1<method-wrapper u?'__init__' of MyList object at )rBrCrb�appendrsrE)rirrmrys    r!�test_wrapper_callzPyBtTests.test_wrapper_call�s����o��
�
��"6�z� B���	1�
"�(�(��0�0�0��$�$�W�-�-�-��)�)�#�@U�*�W�W�
�����M�	O�	O�	O�	O�	Or4N)r�r�r�rr%rr+r.r3r7rJrMr^r4r!r'r's{�������X�_�(�(�*�*�=�?�?���?�?��$�X�_�(�(�*�*�=�?�?���?�?���X�_�(�(�*�*�=�?�?�9�9�?�?�9�@�X�_�(�(�*�*�=�?�?�
8�8�?�?�
8�,�X�_�(�(�*�*�=�?�?�88�88�?�?�88�t�X�_�(�(�*�*�=�?�?�O�O�?�?�O�O�Or4r'c�L�eZdZeje��d��d���Zeje��d��ejed��d�����Z	eje��d��d���Z
eje��d��d���ZdS)�PyPrintTestsrc�p�	|�tddg���}|�|d��dS)Nrz
py-print argsrz".*\nlocal 'args' = \(1, 2, 3\)\n.*rrs  r!r
zPyPrintTests.test_basic_command�sZ��	3�
�
!�
!�);�9@�/�8R�"�T�T���#�#�B�$I�	K�	K�	K�	K�	Kr4rc�n�|�tgd����}|�|d��dS)N)rrz
py-print cz
py-print bz
py-print arz3.*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*rrs  r!�test_print_after_upz PyPrintTests.test_print_after_up�sX���
!�
!�);�8t�8t�8t�"�v�v���#�#�B�$Z�	\�	\�	\�	\�	\r4c��|�|���ddg���}|�|d��dS)Nrzpy-print __name__r	z&.*\nglobal '__name__' = '__main__'\n.*r*rs  r!�test_printing_globalz!PyPrintTests.test_printing_global�sc���
!�
!��)?�)?�)A�)A�9@�BU�8V�"�X�X���#�#�B�$M�	O�	O�	O�	O�	Or4c��|�|���ddg���}|�|d��dS)Nrzpy-print lenr	zV.*\nbuiltin 'len' = <built-in method len of module object at remote 0x-?[0-9a-f]+>\n.*r*rs  r!�test_printing_builtinz"PyPrintTests.test_printing_builtin�sb���
!�
!��)?�)?�)A�)A�9@�.�8Q�"�S�S���#�#�B�$}�	�	�	�	�	r4N)r�r�r�rr%rr
r#r$rRrTrVr^r4r!rOrO�s(�������X�_�(�(�*�*�=�?�?�K�K�?�?�K��X�_�(�(�*�*�=�?�?��X���*P�Q�Q�\�\�R�Q�?�?�\��X�_�(�(�*�*�=�?�?�O�O�?�?�O��X�_�(�(�*�*�=�?�?���?�?���r4rOc���eZdZeje��d��d���Zejed��eje��d��d�����Z	dS)�
PyLocalsTestsrc��|�|���ddg���}|�|d��dS)Nr�	py-localsr	z.*\nargs = \(1, 2, 3\)\n.*r*rs  r!r
z PyLocalsTests.test_basic_command�sb���
!�
!��)?�)?�)A�)A�9@�+�8N�"�P�P���#�#�B�$A�	C�	C�	C�	C�	Cr4rc��|�|���gd����}|�|d��dS)N)rrrZr	z<^.*
Locals for foo
a = 1
b = 2
c = 3
Locals for <module>
.*$r*rs  r!�test_locals_after_upz"PyLocalsTests.test_locals_after_ups`���
!�
!��)?�)?�)A�)A�8W�8W�8W�"�Y�Y���#�#�B�%�	�	�	�	�	r4N)
r�r�r�rr%rr
r#r$r\r^r4r!rXrX�s��������X�_�(�(�*�*�=�?�?�C�C�?�?�C��X���*P�Q�Q��X�_�(�(�*�*�=�?�?�
�
�?�?�R�Q�
�
�
r4rXc��tjrNtdt�dt�d���t
���D]}td|z���dSdS)NzGDB version r$�:z    )r�verboserhrFrG�gdb_versionrg)rqs r!�setUpModulerass����"�
��&7�&7�&7�9J�9J�9J�K�L�L�L��*�*�,�,�	"�	"�D��'�D�.�!�!�!�!�"�"�	"�	"r4�__main__)4rB�platformrrrcr5rBr�testr�test.supportrrr"r`rFrGr�is_python_build�python_compilerr6�pathr�dirnamerdrHr`r;rbrO�
gdbpy_versionrR�gdbpy_errorsr}r�rUr$rvr%�PGO�TestCaserXr�rrrr'rOrXrar��mainr^r4r!�<module>ros���
�	�	�	�����	�	�	�	�����
�
�
�
�������������������6�6�6�6�6�6�6�6�?�?�?�<5D�O�4E�4E�1��
� 1��q���
�(�
�
�0�0�0�2C�2C�2C�*�{�,�-�-�-�
!�y� �"�"�S�
�(�
�Q�
R�
R�R�
�&�h�&�(�(�(�(�S�\�X�-E�-E�
�(�
�5�6�6�6��Y��1�2�2�;�e��Y��.�/�/�5�2�7�7�
�(�
�D�
E�
E�E��W�\�\�"�'�/�/�#�.�"A�"A�"1�3�3����
(�
(�
(� ��!�!��J�J�J�6�7�V�W�W��
�q��J�
�(�
�H�
I�
I�I��
���
�(�
�5�
6�
6�6��'�(�C�N�3�3���<�#�|�3�3�
?�C�
�(�
�C�,�"5�"5�"7�"7�7�
8�
8�8�'�'�'�'�&�(�(���
������2�3�3�_)�_)�_)�_)�_)�H�%�_)�_)�4�3�_)�B}\�}\�}\�}\�}\�}�}\�}\�}\�~���$�$�&�&�9�;�;�&�&�&�&�&�-�&�&�;�;�&�P��$*�*�*�*�*�=�*�*�*�X~O�~O�~O�~O�~O�
�~O�~O�~O�@!�!�!�!�!�=�!�!�!�F�����M����2"�"�"��z����H�M�O�O�O�O�O��r4