Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_gdb.cpython-34.pyc

�
f fԒ�
@s�ddlZddlZddlZddlZddlZddlZddlZddlZyddlZWne	k
r�dZYnXddl
mZddlm
Z
mZmZdd�Ze�\ZZZedkrejdeeef��nej�rejd��nejjejjej�d	�Zd
Zdd�Zed
�\ZZer�ejd��ndejgZedej�\ZZ de kr�dZ!eje!e j"���ndd�Z#e#�Z$dZ%Gdd�dej&�Z'Gdd�de'�Z(ej)e�d�Gdd�de'��Z*Gdd�de'�Z+Gdd�de'�Z,Gd d!�d!e'�Z-Gd"d#�d#e'�Z.d$d%�Z/e0d&kr�e/�ndS)'�N)�support)�run_unittest�findfile�python_is_optimizedcCs�yHtjdddgdtjdd�}|�|j�d}WdQXWn!tk
rktjd��YnXtjd	|�}|dkr�t	d
|��n|t
|jd��t
|jd��fS)
N�gdbz-nxz	--version�stdoutZuniversal_newlinesTrzCouldn't find gdb on the pathz^GNU gdb.*?\b(\d+)\.(\d+)zunable to parse GDB version: %r��)�
subprocess�Popen�PIPE�communicate�OSError�unittest�SkipTest�re�search�	Exception�int�group)�proc�version�match�r�2/opt/alt/python34/lib64/python3.4/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.z
python-gdb.pyZ123c
Os�|r%tjj�}|j|�nd}d}ttfdkrZ|ddtf7}ntj||d	tj	d
tj	d|�}|�|j
�\}}WdQX|jdd
�|jdd
�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.
    Nr�--batch�-nxr�z-iexzadd-auto-load-safe-path r�stderr�envzutf-8�replace)zgdbrr)rr)�os�environ�copy�update�gdb_major_version�gdb_minor_version�checkout_hook_pathr
rrr
�decode)�argsZenv_varsr!Zbase_cmdr�out�errrrr�run_gdb>s			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�\}}tjd|�}|s<tjd��n|jd�jd�}d|kS)Nz+--eval-command=python print(dir(gdb.Frame))z.*\[(.*)\].*z1Unable to parse output from gdb.Frame.select testrz, z'select')r.rrrrr�split)r�_�mZ
gdb_frame_dirrrr�gdb_has_frame_selectbsr2�
builtin_idc@sgeZdZdZddedddd�Zdddd�Zdd	�Zd
d�Zdd
�Z	dS)�
DebuggerTestsz(Test that the debugger can debug Python.NFcCsodd|ddg}ttfdkr8|dg7}n|rK||7}n
|dg7}d	d
dg}|dd
�|D�7}|dtjg7}|s�|dg7}n|r�|d|g7}n|r�||g7}ntdt|�\}}	|	j�}
g}d|ddddddddddf}x-|
D]%}
|
j|�s2|j|
�q2q2W|j	|g�|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 offZrunrrzset print entry-values no�	backtracerz--batchz-nxcSsg|]}d|�qS)z--eval-command=%sr)�.0�cmdrrr�
<listcomp>�s	z1DebuggerTests.get_stack_trace.<locals>.<listcomp>z--argsz-Sz-c�PYTHONHASHSEEDzFunction "%s" not defined.zLwarning: no loadable sections found in added symbol-file system-supplied DSOzpwarning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.zLwarning: Cannot initialize thread debugging library: Debugger service failedz@warning: Could not load shared library symbols for linux-vdso.soz@warning: Could not load shared library symbols for linux-gate.sozBwarning: Could not load shared library symbols for linux-vdso64.soz5Do you need "set solib-search-path" or "set sysroot"?z4warning: Source file is more recent than executable.zMissing separate debuginfo for zTry: zypper install -C )rr)
r'r(�sys�
executabler.r9�
splitlines�
startswith�append�assertEqual)�self�source�script�
breakpoint�cmds_after_breakpoint�import_siteZcommandsr+r,r-ZerrlinesZunexpected_errlinesZignore_patterns�linerrr�get_stack_tracessL
	


	
zDebuggerTests.get_stack_tracecCs{|pdg}|j|dtd|d|�}tjd|tj�}|sh|jd||f�n|jd�|fS)Nzbacktrace 1rCrDrEzh.*#0\s+(?: 0x[0-9a-f]+\s+in\s+)?builtin_id\s+\(self\=.*,\s+v=\s*(.*?)\)\s+at\s+\S*Python/bltinmodule.c.*zUnexpected gdb output: %r
%sr)rG�
BREAKPOINT_FNrr�DOTALL�failr)r@rArDrE�
gdb_outputr1rrr�get_gdb_repr�s		zDebuggerTests.get_gdb_reprcCs*|j|j|�dd||f�dS)z9Ensure that the given "actual" string ends with "exp_end"�msgz%r did not end with %rN)�
assertTrue�endswith)r@�actualZexp_endrrr�assertEndsWithszDebuggerTests.assertEndsWithcCs?tj||tj�}|s;|jdd||f�ndS)NrMz%r did not match %r)rrrIrJ)r@rP�patternr1rrr�assertMultilineMatchessz$DebuggerTests.assertMultilineMatchescCs
td�S)Nz
gdb_sample.py)r)r@rrr�get_sample_scriptszDebuggerTests.get_sample_script)
�__name__�
__module__�__qualname__�__doc__rHrGrLrQrSrTrrrrr4osor4c@sreZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�ZdS)<�PrettyPrintTestscCs&|jd�}|jt|k�dS)Nzid(42))rGrNrH)r@rKrrr�test_getting_backtracesz'PrettyPrintTests.test_getting_backtraceNcCs\|jdt|�d�\}}|s8t|�}n|j||d|||f�dS)Nzid(�)z1%r did not equal expected %r; full output was:
%s)rL�ascii�reprr?)r@�valZexp_repr�gdb_reprrKrrr�
assertGdbReprs#zPrettyPrintTests.assertGdbReprcCsE|jd�|jd�|jd�|jd�|jd�dS)	z0Verify the pretty-printing of various int values�*rrlJ)�l�I�5Ni����l�����I�5)r`)r@rrr�test_ints




zPrettyPrintTests.test_intcCs+|jd�|jd�|jd�dS)z2Verify the pretty-printing of True, False and NoneTFN)r`)r@rrr�test_singletons%s

z PrettyPrintTests.test_singletonscCsF|ji�|jidd6d�|jidd6dd6d�dS)z*Verify the pretty-printing of dictionaries�bar�fooz{'foo': 'bar'}raZdouglasz{'douglas': 42, 'foo': 'bar'}N)r`)r@rrr�
test_dicts+s
zPrettyPrintTests.test_dictscCs*|jg�|jttd���dS)z#Verify the pretty-printing of lists�N)r`�list�range)r@rrr�
test_lists1s
zPrettyPrintTests.test_listscCsk|jd�|jd�|jd�|jd�|jd�|jtdd�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)r6�brrrr8Bs	z/PrettyPrintTests.test_bytes.<locals>.<listcomp>�N)r`�bytesri)r@rrr�
test_bytes6s




zPrettyPrintTests.test_bytescsptj����fdd�}�jd��jd��jd�|d�|d�|td��d	S)
z-Verify the pretty-printing of unicode stringscsSy|j��d}Wn(tk
rA�j|t|��YnX�j|�dS)NT)�encode�UnicodeEncodeErrorr`r\)�textZ	printable)�encodingr@rr�
check_reprGs


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)�locale�getpreferredencodingr`�chr)r@rtr)rsr@r�test_stringsDs	




zPrettyPrintTests.test_stringscCs4|jt�d�|jdd�|jd	�dS)
z$Verify the pretty-printing of tuplesz()rz(1,)rerd�bazN)r)zfoozbarrz)r`�tuple)r@rrr�test_tuplesdszPrettyPrintTests.test_tuplescCs�ttfdkr"|jd�n|jt�d�|jtddg�d�|jtdd	d
g�d�|jd�\}}|j|d
�dS)z"Verify the pretty-printing of setsr�z.pretty-printing of sets needs gdb 7.3 or laterzset()�arlz
{'a', 'b'}rrg�z	{4, 5, 6}z&s = set(['a','b'])
s.remove('a')
id(s)z{'b'}N)rr})r'r(�skipTestr`�setrLr?)r@r_rKrrr�	test_setsjszPrettyPrintTests.test_setscCstttfd
kr"|jd�n|jt�d�|jtddg�d�|jtdd	d
g�d�dS)z(Verify the pretty-printing of frozensetsrr}z4pretty-printing of frozensets needs gdb 7.3 or laterzfrozenset()r~rlzfrozenset({'a', 'b'})rrgrzfrozenset({4, 5, 6})N)rr})r'r(r�r`�	frozenset)r@rrr�test_frozensetsys
z PrettyPrintTests.test_frozensetscCsN|jd�\}}|j|d�|jd�\}}|j|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',))rLr?)r@r_rKrrr�test_exceptions�s		z PrettyPrintTests.test_exceptionscCsB|jd�\}}tjd|�}|j|dd|�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]+>rMz'Unexpected new-style class rendering %rN)rLrrrN)r@r_rKr1rrr�test_modern_class�s
z"PrettyPrintTests.test_modern_classcCsB|jd�\}}tjd|�}|j|dd|�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]+>rMz'Unexpected new-style class rendering %rN)rLrrrN)r@r_rKr1rrr�test_subclassing_list�s
z&PrettyPrintTests.test_subclassing_listcCsB|jd�\}}tjd|�}|j|dd|�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]+>rMz'Unexpected new-style class rendering %rN)rLrrrN)r@r_rKr1rrr�test_subclassing_tuple�s
z'PrettyPrintTests.test_subclassing_tuplec	Cs�|r|dg}n	dg}|j|d|�\}}|rR||krRdSnd}tj||�}|s�|jd||f�ndS)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
        representationr5rDNz<.* at remote 0x-?[0-9a-f]+>z$Unexpected gdb representation: %r
%s)rLrrrJ)	r@rAZ
corruption�expreprrDr_rKrRr1rrr�
assertSane�s		zPrettyPrintTests.assertSanecCs5|jddddg�\}}|j|d�dS)z2Ensure that a NULL PyObject* is handled gracefullyzid(42)rDzset variable v=0r5Z0x0N)rLr?)r@r_rKrrr�
test_NULL_ptr�szPrettyPrintTests.test_NULL_ptrcCs|jdd�dS)z?Ensure that a PyObject* with NULL ob_type is handled gracefullyzid(42)zset v->ob_type=0N)r�)r@rrr�test_NULL_ob_type�s	z"PrettyPrintTests.test_NULL_ob_typecCs|jdddd�dS)zDEnsure that a PyObject* with a corrupt ob_type is handled gracefullyzid(42)zset v->ob_type=0xDEADBEEFr��42N)r�)r@rrr�test_corrupt_ob_type�s	z%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�)r@rrr�test_corrupt_tp_flags�s	z&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�)r@rrr�test_corrupt_tp_name�s	z%PrettyPrintTests.test_corrupt_tp_namecCsH|jddd�\}}tjd|�}|j|dd|�dS)zAEnsure that the new-style class _Helper in site.py can be handledzid(__builtins__.help)rETz!<_Helper at remote 0x-?[0-9a-f]+>rMzUnexpected rendering %rN)rLrrrN)r@r_rKr1rrr�test_builtins_help�sz#PrettyPrintTests.test_builtins_helpcCsN|jd�\}}|j|d�|jd�\}}|j|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)rLr?)r@r_rKrrr�test_selfreferential_listsz*PrettyPrintTests.test_selfreferential_listcCs)|jd�\}}|j|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)rLr?)r@r_rKrrr�test_selfreferential_dictsz*PrettyPrintTests.test_selfreferential_dictcCs?|jd�\}}|jtjd|�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)rLrNrr)r@r_rKrrr�'test_selfreferential_old_style_instancesz8PrettyPrintTests.test_selfreferential_old_style_instancecCsz|jd�\}}|jtjd|�d||f�|jd�\}}|jtjd|�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]+>)rLrNrr)r@r_rKrrr�'test_selfreferential_new_style_instance(sz8PrettyPrintTests.test_selfreferential_new_style_instancecCsI|jd�\}}|j|d�|jt|�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)rLr?�len)r@r_rKrrr�test_truncationCs
	z PrettyPrintTests.test_truncationcCs?|jd�\}}|jtjd|�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)rLrNrr)r@r_rKrrr�test_builtin_method_s
z$PrettyPrintTests.test_builtin_methodcCsN|jdddddg�}|jtjd|tj�d||f�dS)Nz:
def foo(a, b, c):
    pass

foo(3, 4, 5)
id(foo.__code__)rCr3rDz:print (PyFrameObject*)(((PyCodeObject*)v)->co_zombieframe)zM.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*z$Unexpected gdb representation: %r
%s)rGrNrrrI)r@rKrrr�test_framesfs	zPrettyPrintTests.test_frames) rUrVrWrZr`rbrcrfrjroryr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrYs:
 


rYz&Python was compiled with optimizationsc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�PyListTestscCs|j||�dS)N)rQ)r@ZexpectedrPrrr�
assertListingxszPyListTests.assertListingcCs5|jd|j�ddg�}|jd|�dS)z'Verify that the "py-list" command worksrBrDzpy-listz�   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)rGrTr�)r@�btrrr�test_basic_command{s	zPyListTests.test_basic_commandcCs5|jd|j�ddg�}|jd|�dS)z7Verify the "py-list" command with one absolute argumentrBrDz	py-list 9zI   9    def baz(*args):
 >10        id(42)
  11    
  12    foo(1, 2, 3)
N)rGrTr�)r@r�rrr�test_one_abs_arg�s	zPyListTests.test_one_abs_argcCs5|jd|j�ddg�}|jd|�dS)z8Verify the "py-list" command with two absolute argumentsrBrDzpy-list 1,3zR   1    # Sample script for use by test_gdb.py
   2    
   3    def foo(a, b, c):
N)rGrTr�)r@r�rrr�test_two_abs_args�s	zPyListTests.test_two_abs_argsN)rUrVrWr�r�r�r�rrrrr�usr�c@s�eZdZejed�eje�d�dd���Zejed�dd��Z	ejed�dd��Z
ejed�eje�d�d	d
���ZdS)�StackNavigationTestsz$test requires py-up/py-down commandsz&Python was compiled with optimizationscCs5|jd|j�ddg�}|j|d�dS)z%Verify that the "py-up" command worksrBrDzpy-upzp^.*
#[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)rGrTrS)r@r�rrr�test_pyup_command�s	z&StackNavigationTests.test_pyup_commandcCs5|jd|j�ddg�}|j|d�dS)z7Verify handling of "py-down" at the bottom of the stackrBrDzpy-downz$Unable to find a newer python frame
N)rGrTrQ)r@r�rrr�test_down_at_bottom�s	z(StackNavigationTests.test_down_at_bottomcCs9|jd|j�ddgd�}|j|d�dS)z2Verify handling of "py-up" at the top of the stackrBrDzpy-uprz%Unable to find an older python frame
N)rGrTrQ)r@r�rrr�test_up_at_top�s	z#StackNavigationTests.test_up_at_topcCs8|jd|j�dddg�}|j|d�dS)z$Verify "py-up" followed by "py-down"rBrDzpy-upzpy-downz�^.*
#[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)rGrTrS)r@r�rrr�test_up_then_down�s	z&StackNavigationTests.test_up_then_downN)rUrVrWr�
skipUnless�HAS_PYUP_PYDOWN�skipIfrr�r�r�r�rrrrr��sr�c@s�eZdZeje�d�dd��Zeje�d�dd��Zeje	d�dd��Z
eje�d�eje	d�d	d
���Zeje�d�eje	d�dd���Zd
S)�	PyBtTestsz&Python was compiled with optimizationscCs5|jd|j�ddg�}|j|d�dS)z%Verify that the "py-bt" command worksrBrDzpy-bta^.*
Traceback \(most recent call first\):
  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)rGrTrS)r@r�rrr�test_bt�s	zPyBtTests.test_btcCs5|jd|j�ddg�}|j|d�dS)z*Verify that the "py-bt-full" command worksrBrDz
py-bt-fulla>^.*
#[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)rGrTrS)r@r�rrr�test_bt_full�s	zPyBtTests.test_bt_fullz*Python was compiled without thread supportcCsZd}|j|ddg�}|jd|�|j|ddg�}|jd|�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)

rDzthread apply all py-btzWaiting for the GILzthread apply all py-bt-fullN)rG�assertIn)r@r7rKrrr�test_threads�szPyBtTests.test_threadscCsfd}|j|ddddg�}|jd|�|j|ddddg�}|jd|�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()
rDzbreak update_refs�continuezpy-btzGarbage-collectingz
py-bt-fullN)rGr�)r@r7rKrrr�test_gcs	zPyBtTests.test_gccCsid}|j|dddddg�}|jd|�|j|ddddg�}|jd	|�d
S)zAVerify that "py-bt" displays invocations of PyCFunction instanceszJfrom time import sleep
def foo():
    sleep(1)
def bar():
    foo()
bar()
rCZ
time_sleeprDr�zpy-btz<built-in method sleepz
py-bt-fullz#0 <built-in method sleepN)rGr�)r@r7rKrrr�test_pycfunction.s	zPyBtTests.test_pycfunctionN)
rUrVrWrr�rr�r�r��_threadr�r�r�rrrrr��s	!		r�c@s�eZdZeje�d�dd��Zeje�d�ejed�dd���Z	eje�d�dd��Z
eje�d�d	d
��ZdS)�PyPrintTestsz&Python was compiled with optimizationscCs5|jd|j�ddg�}|j|d�dS)z(Verify that the "py-print" command worksrBrDz
py-print argsz".*\nlocal 'args' = \(1, 2, 3\)\n.*N)rGrTrS)r@r�rrrr�Ms	zPyPrintTests.test_basic_commandz$test requires py-up/py-down commandscCs>|jd|j�dddddg�}|j|d�dS)NrBrDzpy-upz
py-print cz
py-print bz
py-print az3.*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*)rGrTrS)r@r�rrr�test_print_after_upVs	z PyPrintTests.test_print_after_upcCs5|jd|j�ddg�}|j|d�dS)NrBrDzpy-print __name__z&.*\nglobal '__name__' = '__main__'\n.*)rGrTrS)r@r�rrr�test_printing_global_s	z!PyPrintTests.test_printing_globalcCs5|jd|j�ddg�}|j|d�dS)NrBrDzpy-print lenzV.*\nbuiltin 'len' = <built-in method len of module object at remote 0x-?[0-9a-f]+>\n.*)rGrTrS)r@r�rrr�test_printing_builtings	z"PyPrintTests.test_printing_builtinN)rUrVrWrr�rr�r�r�r�r�r�rrrrr�Ls!r�c@sdeZdZeje�d�dd��Zejed�eje�d�dd���Z	dS)�
PyLocalsTestsz&Python was compiled with optimizationscCs5|jd|j�ddg�}|j|d�dS)NrBrDz	py-localsz.*\nargs = \(1, 2, 3\)\n.*)rGrTrS)r@r�rrrr�ps	z PyLocalsTests.test_basic_commandz$test requires py-up/py-down commandscCs8|jd|j�dddg�}|j|d�dS)NrBrDzpy-upz	py-localsz.*\na = 1\nb = 2\nc = 3\n.*)rGrTrS)r@r�rrr�test_locals_after_upxs	z"PyLocalsTests.test_locals_after_upN)
rUrVrWrr�rr�r�r�r�rrrrr�os
r�cCsbtjrEtdttf�x%tj�D]}td|�q*Wnttt	t
ttt
�dS)NzGDB version %s.%s:� rz    )r�verbose�printr'r(�gdb_versionr<rrYr�r�r�r�r�)rFrrr�	test_main�s	r��__main__)1r#r�pprintr
r:�	sysconfigrrvr��ImportErrorZtestrZtest.supportrrrrr�r'r(r�is_python_build�path�join�dirnamer;r)r9r.Z
gdbpy_versionr0r7Zgdbpy_errorsrM�rstripr2r�rHZTestCaser4rYr�r�r�r�r�r�r�rUrrrr�<module>sb
	
			��h(-�#