
    J/Phw!                        d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	 d dl
mZmZmZ d dlmZmZ e j                            e          Zej        Ze                    d          pe                    d          pdev Zdd
Z ee          d             Z ee          d             Z	 ddZd Z ee          d             Zd ZdS )    N)ir)typesutilsconfigcgutilserrors)gdbgdb_initgdb_breakpoint)overload	intrinsiclinuxdarwinbsdTc                    t           sd}t          j        |          t          j        }t
          j                            |          rt
          j                            |          sd}t          |t          j        z            t
          j        
                    t
          j        ddddd          }t
          j                            |          }|ret          |d          5 }|                                                                }d	d	d	           n# 1 swxY w Y   | r|d
vrd}t          |          d	S d	S d	S )aF  
    Set need_ptrace_attach to True/False to indicate whether the ptrace attach
    permission is needed for this gdb use case. Mode 0 (classic) or 1
    (restricted ptrace) is required if need_ptrace_attach is True. See:
    https://www.kernel.org/doc/Documentation/admin-guide/LSM/Yama.rst
    for details on the modes.
    z2gdb support is only available on unix-like systemszIs gdb present? Location specified (%s) does not exist. The gdb binary location can be set using Numba configuration, see: https://numba.readthedocs.io/en/stable/reference/envvars.htmlprocsyskernelyamaptrace_scopertN)01a  gdb can launch but cannot attach to the executing program because ptrace permissions have been restricted at the system level by the Linux security module 'Yama'.

Documentation for this module and the security implications of making changes to its behaviour can be found in the Linux Kernel documentation https://www.kernel.org/doc/Documentation/admin-guide/LSM/Yama.rst

Documentation on how to adjust the behaviour of Yama on Ubuntu Linux with regards to 'ptrace_scope' can be found here https://wiki.ubuntu.com/Security/Features#ptrace.)
_unix_liker   NumbaRuntimeErrorr   
GDB_BINARYospathexistsisfileRuntimeErrorjoinsepopenreadlinestrip)need_ptrace_attachmsggdblocptrace_scope_filehas_ptrace_scopefvalues          S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/misc/gdb_hook.py_confirm_gdbr/      sy     ,B&s+++FGNN6"" 4rw~~f'='= 4O 3!22333 RVVUHf%35 5w~~&788 $#T** 	)aJJLL&&((E	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	$%z"9"9
GC s###$ $	$ 	$"9"9s   %'DDDc                  N    t                       t          | d          fd}|S )NTc                                    d S N argsgdbimpls    r.   implzhook_gdb.<locals>.implA       					    r/   gen_gdb_implr5   r7   r6   s     @r.   hook_gdbr=   <   s9    NNN4&&G    Kr9   c                  N    t                       t          | d          fd}|S )NFc                                    d S r2   r3   r4   s    r.   r7   zhook_gdb_init.<locals>.implK   r8   r9   r:   r<   s     @r.   hook_gdb_initr@   F   s9    NNN4''G    Kr9   Fc                    ( t          j        d          }t          j        d          }t          j        t          j                  }t          j        t          j        d                    }	 |d          }
|j        (t          j        ||d          }t          j        ||d          }                     (d          }                     (t          j
                  }                     (d          }g }|                    d	t          j                            t          d
          g           |                    ddg           t!          d |D                       rt#          j        |          |                    d |D                         (fd|D             }t          j        |t)                                }t          j        (|d          }t          j        ||	||	fd          }t          j        (|d          }t          j        |t)                                }t          j        (|d          }t          j        ||	|	fd          }t          j        (|d          }t          j        ||f          }t          j        (|d          }t          j        t          j                    t)                                }t          j        (|d          }|                    |t)                                }|                    ||           |                    ||
gd          }|                    |          }|                    || |d          ||f          }|                    d| |d                    }|                    |d          5  d} j                            |t>          |f           d d d            n# 1 swxY w Y   |                    |t)                                }|                    d| |d                    } |                    | d          5  d} j                            |t>          |f           d d d            n# 1 swxY w Y   |                    d||
          }!|                     |!          5 \  }"}#|"5  t          j!        |	d           }$|                    ||
gd          }%|                    ||
gd          }&t          j"        |d |           |%|%|&|f}'|'t)          |          z   |$fz   }'|                    ||'           d d d            n# 1 swxY w Y   |#5  |                    | |d!          f           |du r"|                    |t)                                 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )"N       r      )size   z%dattachz-xzcmdlang.gdbz-excc                 D    g | ]}t          |t          j                   S r3   )
isinstancer   StringLiteral.0xs     r.   
<listcomp>z$init_gdb_codegen.<locals>.<listcomp>m   s(    GGGq
1e1222GGGr9   c                     g | ]	}|j         
S r3   )literal_valuerL   s     r.   rO   z$init_gdb_codegen.<locals>.<listcomp>o   s    999Q_999r9   c                 <    g | ]}                     |          S r3   )insert_const_string)rM   rN   cgctxmods     r.   rO   z$init_gdb_codegen.<locals>.<listcomp>p   s)    CCCQu((a00CCCr9   getpidT)var_argsnprintfforkexeclsleepnumba_gdb_breakpoint)inbounds>F)likelyz8Internal error: `snprintf` buffer would have overflowed.z==zInternal error: `fork` failed.zAttaching to PID: %s

   )#r   IntTyper   MACHINE_BITSPointerTypemoduler   alloca_oncerS   r   r   extendr   r   r"   _pathanyr   RequireLiteralValueFunctionTypetupleget_or_insert_functionVoidTypecallstoregeploadicmp_signedif_then	call_convreturn_user_excr!   if_elseConstantprintf))rT   builder	signaturer5   
const_argsdo_breakint8_tint32_tintp_tchar_ptr	zero_i32tpidpidstrintfmtgdb_str
attach_strnew_argscmdlangfntyrV   rX   rY   rZ   r[   
breakpoint
parent_pid
pidstr_ptrpid_valstatinvalid_writer(   	child_pidfork_failedis_childthenorelsenullptrgdb_str_ptrattach_str_ptrbufrU   s)   `                                       @r.   init_gdb_codegenr   P   s    Z]]FjnnGZ*++F~bjmm,,H

I
.C

gwQ
7
7
7C  &r:::F &&sD11F''V->??G**399JH
 OOT27<<}==>???OOUCL!!!
GGJGGGHH 5(444OO99j999:::CCCCC(CCCG ?7EGG,,D+Cx@@F ?(FH-t= = =D-c4DDH ?7EGG,,D)#tV<<D ?7Xx$8$GGGD*3g>>E ?7WJ//D*3g>>E ?2;==%''22D/T0FH HJ fegg..JMM*c"""Vi[4@@Jll3G <<:vvbzz67;= =D''T772;;??M	u	5	5 G GH''vFFFG G G G G G G G G G G G G G G
 T577++I%%dIwwr{{CCK	U	3	3 G G.''vFFFG G G G G G G G G G G G G G G ""4I>>H		"	" 2ntV 	% 	%k(D11G!++)t & 5 5K$[[YK$ ) 8 8NN16; ; ; 	C
 g&'3CLL$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%   	2 	2LL///4Z111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2#2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s   *%OO"O?%Q00Q47Q4'W-BU	=W	U	WU	WAV)W)V-	-W0V-	1WWWc                 0     t            fd            }|S )Nc                 >    t          j                    }fd}||fS )Nc                 n    t          | |||           |                     t          j        d           S )N)r}   )r   get_constantr   none)rT   rz   r{   r5   r|   r}   s       r.   codegenz3gen_gdb_impl.<locals>.gdb_internal.<locals>.codegen   s?    UGYj&.0 0 0 0%%ej$777r9   r   void)tyctxfunction_sigr   r|   r}   s      r.   gdb_internalz"gen_gdb_impl.<locals>.gdb_internal   s9    z||	8 	8 	8 	8 	8 	8 W$$r9   r   )r|   r}   r   s   `` r.   r;   r;      s4    % % % % % Y% r9   c                      t           j                            d          st          d          t	                      fd} | S )z4
    Adds the Numba break point into the source
    r   zgdb is only available on linuxc                                     d S r2   r3   )bp_impls   r.   r7   z!hook_gdb_breakpoint.<locals>.impl   r8   r9   )r   platform
startswithr!   gen_bp_impl)r7   r   s    @r.   hook_gdb_breakpointr      sS    
 <""7++ =;<<<mmG    Kr9   c                  &    t           d             } | S )Nc                 6    t          j                    }d }||fS )Nc                 $   |j         }t          j        t          j                    t	                                }t          j        ||d          }|                    |t	                                 |                     t          j
        d           S )Nr\   )re   r   rk   rn   rl   r   rm   ro   r   r   r   )rT   rz   r{   r5   rU   r   r   s          r.   r   z1gen_bp_impl.<locals>.bp_internal.<locals>.codegen   so    .C?2;==%''::D 7T8NP PJLLUWW---%%ej$777r9   r   )r   r   r   s      r.   bp_internalz gen_bp_impl.<locals>.bp_internal   s)    z||	8 	8 	8 W$$r9   r   )r   s    r.   r   r      s#    
% 
% Y
% r9   )T)F) r   r   llvmliter   
numba.corer   r   r   r   r   numbar	   r
   r   numba.core.extendingr   r   r   dirname__file__rh   r   	_platformr   r   r/   r=   r@   r   r;   r   r   r3   r9   r.   <module>r      s   				 



       < < < < < < < < < < < < < < / / / / / / / / / / 4 4 4 4 4 4 4 4
!!L	""7++ #""8,,#	! 
'$ '$ '$ '$T 
#   
(   +0i2 i2 i2 i2X
 
 
 
.
 
 
    r9   