
    daf)                     B   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	  ej                  d      xs dZe j                  j                  e j                  j                  ej                        d      Ze j                  j                  e j                  j                  e      d      ZdZdZd Zd	Zd d
ddZd Z e       \  ZZedk  r! ej4                  ded     ded    de       d Z e        d Z e       Zd Z G d dej>                        Z y)    N)supportgdbzpython-gdb.pyzgdb_sample.py
builtin_id123c                      t         j                  j                         D  ci c]  \  } }| j                  d      s| | c}} S c c}} w )NPYTHON)osenvironitems
startswith)namevalues     -/root/Python-3.12.4/Lib/test/test_gdb/util.pyclean_environmentr      sB    +-::+;+;+= .KD%??8, %K . . .s   A)r   r   T)exitcodecheckc                    t               }|r|j                  |       t        ddg}t        dk\  r|j	                  ddt
         f       |j	                  |       t        j                  |t        j                  t        j                  t        j                  dd|      }|j                  }|j                  }|rG|j                  | k7  r8t        j                  |      }	t        |	 d	|j                   d
|  d|d|	      ||fS )zRuns gdb in --batch mode with the additional arguments given by *args.

    Returns its (stdout, stderr) decoded from utf-8 using the replace handler.
    z--batchz-nx      z--init-eval-commandzadd-auto-load-safe-path utf8backslashreplace)stdinstdoutstderrencodingerrorsenvz failed with exit code z, expected exit code z	:
stdout=z
stderr=)r   updateGDB_PROGRAMGDB_VERSIONextendCHECKOUT_HOOK_PATH
subprocessrunPIPEr   r   
returncodeshlexjoin	Exception)
r   r   argsenv_varsr   cmdprocr   r   cmd_texts
             r   run_gdbr0   !   s   
 
C

8  C f

)./A.BCE 	FJJt>>oo 2D [[F[[FH,::c?8*$;DOO;L M..6Z 8""( ,""(- . 	.
 F    c                  :   	 t        d      \  } }t	        j
                  d|       }|t        d| z        | }t        |j                  d            }t        |j                  d            }||f}||fS # t        $ r}t        j                  d|       d }~ww xY w)Nz	--versionz'Couldn't find gdb program on the path: z ^(?:GNU|HP) gdb.*?\b(\d+)\.(\d+)zunable to parse gdb version: %r      )	r0   OSErrorunittestSkipTestresearchr*   intgroup)r   r   excmatchversion_textmajorminorversions           r   get_gdb_versionrB   K   s    Q - II96BE}9FBCCLAEAEenG'""%  Q "I# OPPQs   A4 4	B=BB)r   r   zIgdb versions before 7.0 didn't support python embedding. Saw gdb version .r3   z:
c                      t        ddt        j                  d      \  } }d|v rt        j                  d|      | st        j                  d|      d| v rt        j                  d	      y )
Nz9--eval-command=python import sys; print(sys.version_info)--argsF)r   zauto-loading has been declinedz;gdb security settings prevent use of custom hooks; stderr: z4gdb not built with embedded python support; stderr: zmajor=2zgdb built with Python 2)r0   sys
executabler6   r7   )r   r   s     r   check_usable_gdbrH   j   s     C#..NFF
 (61j"# 	# j"# 	# F 9:: r1   c                      t        j                  d      } | sy| j                         }d|v xr t        d |D              S )NCFLAGSFz-mcetc              3   f   K   | ])  }|j                  d       xr |j                  d        + yw)z-fcf-protection)z=nonez=returnN)r   endswith).0flags     r   	<genexpr>z!cet_protection.<locals>.<genexpr>   s>      ' __%67 A!]]+?@@A 's   /1)	sysconfigget_config_varsplitany)cflagsflagss     r   cet_protectionrV      sL    %%h/FLLNE  ' ' %' '(r1   c                      t         j                  rdt        dt        d    dt        d    d       t        j                         D ]  } t        d| z           t        dt                t                y y )Nzgdb version r   rC   r3   :z    z
    path: )r   verboseprintr!   GDB_VERSION_TEXT
splitlinesr    )lines    r   setup_moduler^      sg    [^,Ak!n-=Q?@$//1 	"D'D.!	"
;-() r1   c                   0    e Zd ZdZddedddfdZd Zd Zy)DebuggerTestsz(Test that the debugger can debug Python.NFc                 <   dd|z  ddg}t         dk\  r|dgz  }|rt        r|dgz  }||z  }n|dgz  }|D cg c]  }d	|z  	 }	}|	d
t        j                  gz  }	|	j	                  t        j                                |s|	dgz  }	|r|	d|gz  }	n|r|	|gz  }	t        |	dt        i\  }
}|s0|j                         D ]  }t        |t        j                          d|v rt        j                  d      dD ]  }||
v st        j                  |d       |
S c c}w )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
        zset breakpoint pending yeszbreak %szset print address offr%   r   zset print entry-values nonext	backtracez--eval-command=%srE   z-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)(unable to read python frame information)z,Backtrace stopped: frame did not save the PCz ?? ()z found in gdb output)r!   CET_PROTECTIONrF   rG   r"   r$   _args_from_interpreter_flagsr0   rd   r\   rZ   r   r6   r7   )selfsourcescript
breakpointcmds_after_breakpointimport_siteignore_stderrcommandsr-   r+   outerrr]   patterns                 r   get_stack_tracezDebuggerTests.get_stack_trace   sw   : )# $
. & 455H 
 VH$--H%H
 6>>c#c)>>! 	!J;;=>TFNDT6N"DVHD D@@S( -d,- S ## %3 4 4
 	LG$ #~''7+5I(JKK'	L* 
m ?s   Dc                 R    | j                  |j                  |      |d|       y)z9Ensure that the given "actual" string ends with "exp_end"z did not end with msgN)
assertTruerL   )rh   actualexp_ends      r   assertEndsWithzDebuggerTests.assertEndsWith  s'    08>H 	 	Jr1   c                     t        j                  ||t         j                        }|s| j                  |d|       y y )Nz did not match ru   )r8   r=   DOTALLfail)rh   rx   rr   ms       r   assertMultilineMatchesz$DebuggerTests.assertMultilineMatches   s3    HHWfbii0II67CID r1   )__name__
__module____qualname____doc__BREAKPOINT_FNrs   rz   r    r1   r   r`   r`      s)    2%)$#0.2$)&+	zxJ
Er1   r`   )!r	   r8   r(   shutilr$   rF   rP   r6   testr   whichr    pathr)   dirnamerG   r#   __file__SAMPLE_SCRIPTr   rd   r   r!   r0   rB   r[   r7   rH   rV   rf   r^   TestCaser`   r   r1   r   <module>r      s6   	 	    
    fll5!*U WW\\"''//#.."A"13  RWW__X6H. T 'T#. !0 1  +
(

&q>*!KN+;3
	 ;,  
(  !HEH%% HEr1   