
    dafX                         d dl Z d dlZd dlmZ ddlmZmZmZmZ d Z	d Z
 e
       Z ej                   e       d       G d d	e             Zd
Z G d de      Z G d de      Z G d de      Zy)    N)python_is_optimized   )run_gdbsetup_moduleDebuggerTestsSAMPLE_SCRIPTc                      t                y N)r        2/root/Python-3.12.4/Lib/test/test_gdb/test_misc.pysetUpModuler      s    Nr   c                      t        d      \  } }t        j                  d|       }|st        j                  d| d|d      |j                  d      j                  d      }d|v S )	Nz+--eval-command=python print(dir(gdb.Frame))z.*\[(.*)\].*z9Unable to parse output from gdb.Frame.select test
stdout=z
stderr=
r   z, z'select')r   rematchunittestSkipTestgroupsplit)stdoutstderrmgdb_frame_dirs       r   gdb_has_frame_selectr      sw    JKNFF
&)AZ  Zr#$ 	$ GGAJ$$T*M&&r   &Python was compiled with optimizationsc                   $    e Zd Zd Zd Zd Zd Zy)PyListTestsc                 (    | j                  ||       y r
   )assertEndsWith)selfexpectedactuals      r   assertListingzPyListTests.assertListing   s    FH-r   c                 X    | j                  t        dg      }| j                  d|       y)z'Verify that the "py-list" command workszpy-listscriptcmds_after_breakpointz   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get_stack_tracer   r$   r!   bts     r   test_basic_commandzPyListTests.test_basic_command!   s9    !!9B " E 	 4 	r   c                 X    | j                  t        dg      }| j                  d|       y)z7Verify the "py-list" command with one absolute argumentz	py-list 9r&   zI   9    def baz(*args):
 >10        id(42)
  11    
  12    foo(1, 2, 3)
Nr)   r+   s     r   test_one_abs_argzPyListTests.test_one_abs_arg0   s9    !!9D " G 	 4 		r   c                 X    | j                  t        dg      }| j                  d|       y)z8Verify the "py-list" command with two absolute argumentszpy-list 1,3r&   zO   1    # Sample script for use by test_gdb
   2    
   3    def foo(a, b, c):
Nr)   r+   s     r   test_two_abs_argszPyListTests.test_two_abs_args;   s9    !!9F " I 	 9 	r   N)__name__
__module____qualname__r$   r-   r/   r1   r   r   r   r   r      s    .	r   r   z

from _testcapi import pyobject_vectorcall

def foo(a, b, c):
    bar(a, b, c)

def bar(a, b, c):
    pyobject_vectorcall(baz, (a, b, c), None)

def baz(*args):
    id(42)

foo(1, 2, 3)

c                   @   e Zd Z ej                  ed       ej                   e       d      d               Z ej                  ed      d        Z	 ej                  ed      d        Z
 ej                  ed       ej                   e       d      d               Zy)StackNavigationTests$test requires py-up/py-down commandsr   c                 Z    | j                  t        ddg      }| j                  |d       y)z%Verify that the "py-up" command workspy-upsourcer(   z^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
#[0-9]+ <built-in method pyobject_vectorcall of module object at remote 0x[0-9a-f]+>
$Nr*   SAMPLE_WITH_C_CALLassertMultilineMatchesr+   s     r   test_pyup_commandz&StackNavigationTests.test_pyup_commandX   s:    
 !!);9@'8J " L##B%	r   c                 X    | j                  t        dg      }| j                  |d       y)z7Verify handling of "py-down" at the bottom of the stackpy-downr&   z$Unable to find a newer python frame
Nr*   r   r    r+   s     r   test_down_at_bottomz(StackNavigationTests.test_down_at_bottome   s5     !!9B " EBC	Er   c                 ^    | j                  t        dgdz        }| j                  |d       y)z2Verify handling of "py-up" at the top of the stackr9      r&   z%Unable to find an older python frame
NrB   r+   s     r   test_up_at_topz#StackNavigationTests.test_up_at_topm   s9     !!9@	A " GBD	Fr   c                 Z    | j                  t        g d      }| j                  |d       y)z$Verify "py-up" followed by "py-down")r9   r9   rA   r:   a  ^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
#[0-9]+ <built-in method pyobject_vectorcall 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\)\)
$Nr<   r+   s     r   test_up_then_downz&StackNavigationTests.test_up_then_downu   s5    
 !!);8U " W##B%	r   N)r2   r3   r4   r   
skipUnlessHAS_PYUP_PYDOWNskipIfr   r?   rC   rF   rH   r   r   r   r6   r6   W   s    X*PQX__(*=?? R X*PQE RE X*PQF RF X*PQX__(*=?	? R	r   r6   c                   (   e Zd Z ej                   e       d      d        Z ej                   e       d       ej                  ed      d               Z	 ej                   e       d      d        Z
 ej                   e       d      d        Zy)PyPrintTestsr   c                 Z    | j                  t        ddg      }| j                  |d       y)z(Verify that the "py-print" command worksr9   zpy-print argsr:   z".*\nlocal 'args' = \(1, 2, 3\)\n.*Nr<   r+   s     r   r-   zPyPrintTests.test_basic_command   s9     !!);9@/8R " T##B$I	Kr   r7   c                 Z    | j                  t        g d      }| j                  |d       y )N)r9   r9   z
py-print cz
py-print bz
py-print ar:   z3.*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*r<   r+   s     r   test_print_after_upz PyPrintTests.test_print_after_up   s4     !!);8t " v##B$Z	\r   c                 Z    | j                  t        ddg      }| j                  |d       y )Nr9   zpy-print __name__r&   z&.*\nglobal '__name__' = '__main__'\n.*r*   r   r>   r+   s     r   test_printing_globalz!PyPrintTests.test_printing_global   s9     !!9@BU8V " X##B$M	Or   c                 Z    | j                  t        ddg      }| j                  |d       y )Nr9   zpy-print lenr&   zV.*\nbuiltin 'len' = <built-in method len of module object at remote 0x-?[0-9a-f]+>\n.*rR   r+   s     r   test_printing_builtinz"PyPrintTests.test_printing_builtin   s8     !!9@.8Q " S##B$}	r   N)r2   r3   r4   r   rK   r   r-   rI   rJ   rP   rS   rU   r   r   r   rM   rM      s    X__(*=?K?K X__(*=?X*PQ\ R?\ X__(*=?O?O X__(*=??r   rM   c                       e Zd Z ej                   e       d      d        Z ej                  ed       ej                   e       d      d               Z	y)PyLocalsTestsr   c                 Z    | j                  t        ddg      }| j                  |d       y )Nr9   	py-localsr&   z.*\nargs = \(1, 2, 3\)\n.*rR   r+   s     r   r-   z PyLocalsTests.test_basic_command   s8     !!9@+8N " P##B$A	Cr   r7   c                 Z    | j                  t        g d      }| j                  |d       y )N)r9   r9   rY   r&   z<^.*
Locals for foo
a = 1
b = 2
c = 3
Locals for <module>
.*$rR   r+   s     r   test_locals_after_upz"PyLocalsTests.test_locals_after_up   s4     !!8W " Y##B%	r   N)
r2   r3   r4   r   rK   r   r-   rI   rJ   r[   r   r   r   rW   rW      sk    X__(*=?C?C X*PQX__(*=?
? R
r   rW   )r   r   test.supportr   utilr   r   r   r   r   r   rJ   rK   r   r=   r6   rM   rW   r   r   r   <module>r^      s    	  , E E
' '( $&9;&- &;&P $*= *X!= !FM r   