
    daf{                     `    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y)	    N)support)python_is_optimized   )setup_moduleDebuggerTestsCET_PROTECTIONSAMPLE_SCRIPTc                      t                y )N)r        7/root/Python-3.12.4/Lib/test/test_gdb/test_backtrace.pysetUpModuler   	   s    Nr   c                   b   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y)		PyBtTestsz&Python was compiled with optimizationsc                 X    | j                  t        dg      }| j                  |d       y)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   s6     !!9@	 " C##B%	r   c                 X    | j                  t        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_full"   s6     !!9E " H##B%	r   cpuc                     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-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   sg    
* ))#AY@Z * \
+Z8 ))#A^@_ * a
+Z8r   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)r*   r+   r   Nr#   r%   s      r   test_gczPyBtTests.test_gcU   sc     ))#@j * ,
 	*J7 ))#@o * ,
 	*J7r   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_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   sv     oo   "6z B "((0$$W- ))#@U * W
M	Or   N)__name__
__module____qualname__unittestskipIfr   r   r   r   requires_resourcer(   r,   r3   r   r   r   r   r      s    X__(*=??$ X__(*=?? X__(*=?Wu%9 &?9@ X__(*=?
8?
8* X__(*=?O?Or   r   )r/   r7   testr   test.supportr   utilr   r   r   r	   r   r   r   r   r   <module>r=      s,       , L LyO yOr   