+
    Bi                     R   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt Rt] P                  ! R4      t] P                  ! R4      t] ! R	 R
4      4       t] ! R R4      4       tR tR t]
P*                  ! 4       RR l4       tR tRR lt]R 4       tR t. ROtR# )    N)	dataclass)cache)support)run_python_until_endz/usr/bin/stracez@(?P<syscall>[^(]*)\((?P<args>[^)]*)\)\s*[=]\s*(?P<returncode>.+)s-   \+\+\+ exited with (?P<returncode>\d+) \+\+\+c                   ,   a  ] tR t^t o V 3R ltRtV tR# )StraceEventc                N   < V ^8  d   Qh/ S[ ;R&   S[S[ ,          ;R&   S[ ;R&   # )   syscallargs
returncode)strlist)format__classdict__s   "1/usr/lib/python3.14/test/support/strace_helper.py__annotate__StraceEvent.__annotate__   s+     L  s)O  O	      N)__name__
__module____qualname____firstlineno____annotate_func____static_attributes____classdictcell__r   s   @r   r   r      s      r   r   c                   :   a  ] tR t^t o  R tR tV 3R ltRtV tR# )StraceResultc                   V P                   P                  RR4      pVP                  4        Uu. uF  p\        P	                  V4      NK  	  ppV UUu. uFZ  qD'       g   K  \        VR,          VR,          P                  R4       Uu. uF  qUP                  4       NK  	  upVR,          4      NK\  	  upp# u upi u upi u uppi )zParse event_bytes data into system calls for easier processing.

This assumes the program under inspection doesn't print any non-utf8
strings which would mix into the strace output.utf-8surrogateescaper   r   ,r   )event_bytesdecode
splitlines_syscall_regexmatchr   splitstrip)selfdecoded_eventseventmatchesr)   args   &     r   eventsStraceResult.events$   s    
 ))00:KL (224
4   '4 	 
 ;B
 ;BU-Ki(16v1D1DS1IK1I1IKl+-:A
 	
	
 L
s#   B8	C"'C	B=!C=Cc                   RpV. /pV P                  4        F  pVP                  R8X  d   \        VP                  4      ^8  dx   VP                  ^,          P	                  R4      '       dP   VP                  ^,          P                  R^4      ^,          P                  R4      pW9  d   \        4       W!&   K  K  W!,          P                  V4       K  	  V# )zFind all "MARK <X>" writes and use them to make groups of events.

This is useful to avoid variable / overhead events, like those at
interpreter startup or when opening a file so a test can verify just
the small case under study.	__startupwritez"MARK  z\n")	r1   r   lenr   
startswithr*   removesuffixr   append)r,   current_sectionsectionsr.   s   &   r   r<   StraceResult.sections4   s     &#R([[]E}}'CJJ- "#-$(-

1(@(@(K(K #(**Q-"5"5##+|F3  "204H- 3 )007 # r   c                V   < V ^8  d   Qh/ S[ ;R&   S[ ;R&   S[;R&   S[;R&   S[;R&   # )r
   strace_returncodepython_returncoder%   stdoutstderr)intbytes)r   r   s   "r   r   StraceResult.__annotate__   sB           M  M r   r   N)	r   r   r   r   r1   r<   r   r   r   r   s   @r   r    r       s     
F
 7  r   r    c                     V P                   R 8X  d   RV P                  ^,          9   d   R# V P                   R9   d   R# R# )mmapMAP_ANONTF)munmapmprotect)r   r   )calls   &r   _filter_memory_callrL   J   s5     ||v*		!"<||--r   c                V    V  Uu. uF  p\        V4      '       d   K  VNK  	  up# u upi )zFilter out memory allocation calls from File I/O calls.

Some calls (mmap, munmap, etc) can be used on files or to just get a block
of memory. Use this function to filter out the memory related calls from
other calls.)rL   )syscallsrK   s   & r   filter_memoryrO   V   s&     &GXT-@-FDDXGGGs   &&c                  a
 Ro
V
3R lp \        R\        P                  ! V 4      \        .V,           R7      w  o
pT'       d$   S
P
                  '       d   S
P                  T4       S
P                  P                  4       pTP                  R^4      p\        T4      ^8w  d   T! RTRR 4      # \        P                  T^,          4      pT'       g   T! RT^,          R	,          4      # \        TR
,          4      p	T'       d   T	'       d   S
P                  T4       \        S
P
                  T	T^ ,          S
P                  S
P                  R7      #   \         d   pT! RT4      u Rp?# Rp?ii ; i)z`Run strace and return the trace.

Sets strace_returncode and python_returncode to `-1` on error.Nc           	         < \        RRRV  RV: R2P                  R4      S'       d   SP                  MRS'       d   SP                  R7      # RR7      # )   zerror(z	,details=z) = -1r"   r   r?   r@   r%   rA   rB   )r    encodeouterr)reasondetailsress   &&r   _make_error"strace_python.<locals>._make_errorg   sV      !&7+VDKKGT!377s!377, 	,
 (+, 	,r   z-c)__run_using_commandzCaught OSError   
z)Expected strace events and exit code linez)Expected to find returncode in last line.:N2   Nr   rS   i)r   textwrapdedent_strace_binaryOSErrorrcfailrW   r+   rsplitr7   _returncode_regexr)   rC   r    rV   )codestrace_flagscheckr[   cmd_linerW   strippedoutputreturncode_matchr@   rZ   s   &&&       @r   strace_pythonro   `   s@   
 C,2,OOD!!/ 0< ?
X  ww}}H__UA&F
6{aF#CD>+ 	+ )..vay9F!!9S>+ 	+ ,\:;"#&&*;$*1I"ww"ww	( (-  2+S112s   1E E0E+%E0+E0c                     \         P                  ! V4      p\         P                  ! V 4      p \         P                  ! V4      pR V RV  RV R2p\        WA4      pVP                  4       pVR,          # )z#
print("MARK prelude", flush=True)
z 
print("MARK code", flush=True)
z#
print("MARK cleanup", flush=True)
z*
print("MARK __shutdown", flush=True)
    rh   )r`   ra   ro   r<   )rh   ri   preludecleanupto_runtraceall_sectionss   &&&&   r   
get_eventsrv      s{     oog&G??4 Doog&G	 
 	 
F &/E>>#Lr   c                    \        WW#R7      pV'       d   \        V4      pV Uu. uF  qfP                  NK  	  up# u upi )z=Get the syscalls which a given chunk of python code generates)rq   rr   )rv   rO   r   )rh   ri   rq   rr   ignore_memoryr1   evs   &&&&&  r   get_syscallsrz      s7     GMFv&!'(2JJ(((s   <c                      \        R R.RR7      p V P                  ^ 8X  d1   V P                  ^ 8X  d    V P                  4       '       g   Q R4       hR# R# )zimport sys; sys.exit(0)z--trace=%processF)rj   z!Should have parsed multiple callsT)ro   r?   r@   r1   )rZ   s    r   _can_stracer|      sQ    
1+,#%C !c&;&;q&@zz||@@@|r   c                  T   \         P                  R 8w  d   \        P                  ! R4      # R\        P
                  9   d   \        P                  ! R4      # \        P                  ! RRR7      '       d   \        P                  ! R4      # \        P                  ! \        4       R4      # )linuxzLinux only, requires strace.
LD_PRELOADz;Not supported when LD_PRELOAD is intercepting system calls.T)addressmemoryz;LeakSanitizer does not work under ptrace (strace, gdb, etc)zRequires working strace)
sysplatformunittestskiposenvironr   check_sanitizer
skipUnlessr|   r   r   r   requires_stracer      su    
||w}};<<rzz!
 }}Z[[tD99}}Z[[{}.GHHr   )T) r   T)rO   rv   rz   r   ro   r   r    )rer   r`   r   r   dataclassesr   	functoolsr   testr   test.support.script_helperr   rb   compiler(   rg   r   r    rL   rO   requires_subprocessro   rv   rz   r|   r   __all__r   r   r   <module>r      s    	 
  	  !   ;"GIJJ57     . . .`	H 	/( /(d ()  I";r   