
    8\h{                     h    d dl Z d dlZd dlmZ d dlmZ ddlmZmZm	Z	m
Z
 d Z G d de          ZdS )	    N)support)python_is_optimized   )setup_moduleDebuggerTestsCET_PROTECTIONSAMPLE_SCRIPTc                  "    t                       d S )N)r        F/opt/python-3.11.14/usr/lib/python3.11/test/test_gdb/test_backtrace.pysetUpModuler   	   s    NNNNNr   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          d             ZdS )		PyBtTestsz&Python was compiled with optimizationsc                 l    |                      t          dg          }|                     |d           dS )z%Verify that the "py-bt" command workspy-btscriptcmds_after_breakpointaL  ^.*
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get_stack_tracer	   assertMultilineMatchesselfbts     r   test_btzPyBtTests.test_bt   sP     !!9@	 " C C##B%	 	 	 	 	r   c                 l    |                      t          dg          }|                     |d           dS )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_full"   sP     !!9E " H H##B%	 	 	 	 	r   cpuc                     d}|                      |dg          }|                     d|           |                      |dg          }|                     d|           dS )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-btr   zWaiting for the GILzthread apply all py-bt-fullNr   assertInr   cmd
gdb_outputs      r   test_threadszPyBtTests.test_threads2   s    
* ))#AY@Z * \ \
+Z888 ))#A^@_ * a a
+Z88888r   c                     d}|                      |g d          }|                     d|           |                      |g d          }|                     d|           dS )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)r*   r+   r   Nr#   r%   s      r   test_gczPyBtTests.test_gcU   s     ))#@j@j@j * , ,
 	*J777 ))#@o@o@o * , ,
 	*J77777r   c                     t          j        d          }ddg}t          r|                    d           |                    d           |                     ||          }|                     |d           d S )Nz
            class MyList(list):
                def __init__(self):
                    super(*[]).__init__()   # wrapper_call()

            id("first break point")
            l = MyList()
        zbreak wrapper_callr+   nextr   r"   z1<method-wrapper u?'__init__' of MyList object at )textwrapdedentr   appendr   assertRegex)r   r&   r   r'   s       r   test_wrapper_callzPyBtTests.test_wrapper_callo   s     o    "6z B 	1 "((000$$W--- ))#@U * W W
M	O 	O 	O 	O 	Or   N)__name__
__module____qualname__unittestskipIfr   r   r   r   requires_resourcer(   r,   r3   r   r   r   r   r      sW       X_((**=? ? ? ?$ X_((**=? ? ? ? X_((**=? ?Wu%%9 9 &%? ?9@ X_((**=? ?
8 8? ?
8* X_((**=? ?O O? ?O O Or   r   )r/   r7   testr   test.supportr   utilr   r   r   r	   r   r   r   r   r   <module>r=      s            , , , , , , L L L L L L L L L L L L  yO yO yO yO yO yO yO yO yO yOr   