ó
\K]c           @@ s7  d  d l  m Z m Z 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 m Z m Z d  d l m Z m Z e j j e ƒ Z e j Z e j d ƒ pÊ e j d ƒ pÊ d e k Z d	 „  Z e e ƒ d
 „  ƒ Z e e	 ƒ d „  ƒ Z e d „ Z d „  Z e e
 ƒ d „  ƒ Z  d „  Z! d S(   i    (   t   print_functiont   absolute_importN(   t   ir(   t   gdbt   gdb_initt   gdb_breakpointt   typest   utilst   cgutilst   config(   t   overloadt	   intrinsict   linuxt   darwint   bsdc          C@ sì   t  s t d ƒ ‚ n  t j }  t j j |  ƒ o? t j j |  ƒ s^ d } t | t j ƒ ‚ n  t j j t j	 d d d d d ƒ } t j j | ƒ } | rè t
 | d ƒ  } | j ƒ  j ƒ  } Wd  QX| d	 k rè d
 } t | ƒ ‚ qè n  d  S(   Ns2   gdb support is only available on unix-like systemssº   Is gdb present? Location specified (%s) does not exist. The gdb binary location can be set using Numba configuration, see: http://numba.pydata.org/numba-doc/latest/reference/envvars.htmlt   proct   syst   kernelt   yamat   ptrace_scopet   rtt   0s  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.(   t
   _unix_liket   RuntimeErrorR	   t
   GDB_BINARYt   ost   patht   existst   isfilet   joint   sept   opent   readlinet   strip(   t   gdbloct   msgt   ptrace_scope_filet   has_ptrace_scopet   ft   value(    (    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   _confirm_gdb   s    	$	c          @ s)   t  ƒ  t |  t ƒ ‰  ‡  f d †  } | S(   Nc          @ s   ˆ  ƒ  d  S(   N(    (   t   args(   t   gdbimpl(    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   impl:   s    (   R(   t   gen_gdb_implt   True(   R)   R+   (    (   R*   s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   hook_gdb5   s    c          @ s)   t  ƒ  t |  t ƒ ‰  ‡  f d †  } | S(   Nc          @ s   ˆ  ƒ  d  S(   N(    (   R)   (   R*   (    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyR+   D   s    (   R(   R,   t   False(   R)   R+   (    (   R*   s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   hook_gdb_init?   s    c   *      C@ s¢  t  j d ƒ } t  j d ƒ } t  j t j ƒ } t  j t  j d ƒ ƒ }	 | d ƒ }
 | j } t j | | d d ƒ} t j | | d d ƒ} |  j | d ƒ } |  j | t	 j
 ƒ } |  j | d ƒ } g  } | j d	 t j j t d
 ƒ g ƒ | j d d g ƒ | j g  | D] } | j ^ qƒ g  | D] } |  j | | ƒ ^ q+} t  j | t ƒ  ƒ } | j | d ƒ } t  j | |	 | |	 f d t ƒ} | j | d ƒ } t  j | t ƒ  ƒ } | j | d ƒ } t  j | |	 |	 f d t ƒ} | j | d ƒ } t  j | | f ƒ } | j | d ƒ } t  j t  j ƒ  t ƒ  ƒ } | j | d ƒ } | j | t ƒ  ƒ } | j | | ƒ | j | |
 g d t ƒ} | j | ƒ } | j | | | d ƒ | | f ƒ } | j d | | d ƒ ƒ } | j | d t ƒ$ d }  |  j j | t |  f ƒ Wd  QX| j | t ƒ  ƒ }! | j d |! | d ƒ ƒ }" | j |" d t ƒ$ d }  |  j j | t |  f ƒ Wd  QX| j d |! |
 ƒ }# | j  |# ƒ ö \ }$ }% |$ ™ t  j! |	 d  ƒ }& | j | |
 g d t ƒ}' | j | |
 g d t ƒ}( t j# | d | ƒ |' |' |( | f }) |) t | ƒ |& f }) | j | |) ƒ Wd  QX|% @ | j | | d ƒ f ƒ | t k r’| j | t ƒ  ƒ n  Wd  QXWd  QXd  S(   Ni   i    i    t   sizei   i   s   %dt   attachs   -xs   cmdlang.gdbs   -ext   ct   getpidt   var_argt   snprintft   forkt   execlt   sleept   numba_gdb_breakpointt   inboundst   >t   likelys8   Internal error: `snprintf` buffer would have overflowed.s   ==iÿÿÿÿs   Internal error: `fork` failed.s   Attaching to PID: %s
i
   ($   R   t   IntTypeR   t   MACHINE_BITSt   PointerTypet   moduleR   t   alloca_oncet   insert_const_stringR	   R   t   extendR   R   R   t   _patht   literal_valuet   FunctionTypet   tuplet   get_or_insert_functionR-   t   VoidTypet   callt   storet   gept   loadt   icmp_signedt   if_thenR/   t	   call_convt   return_user_excR   t   if_elset   Constantt   Nonet   printf(*   t   cgctxt   buildert	   signatureR)   t
   const_argst   do_breakt   int8_tt   int32_tt   intp_tt   char_ptrt	   zero_i32tt   modt   pidt   pidstrt   intfmtt   gdb_strt
   attach_strt   new_argst   xt   cmdlangt   fntyR4   R6   R7   R8   R9   t
   breakpointt
   parent_pidt
   pidstr_ptrt   pid_valt   statt   invalid_writeR#   t	   child_pidt   fork_failedt   is_childt   thent   orelset   nullptrt   gdb_str_ptrt   attach_str_ptrt   buf(    (    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   init_gdb_codegenI   s‚    	"#%			c         @ s   t  ‡  ‡ f d †  ƒ } | S(   Nc         @ s(   t  j ƒ  } ‡  ‡ f d †  } | | f S(   Nc         @ s/   t  |  | | | ˆ  d ˆ ƒ|  j t j d  ƒ S(   NR[   (   Rz   t   get_constantR   t   noneRU   (   RW   RX   RY   R)   (   RZ   R[   (    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   codegen¸   s    (   R   t   void(   t   tyctxt   function_sigR}   (   RZ   R[   (    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   gdb_internal´   s    (   R   (   RZ   R[   R   (    (   RZ   R[   s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyR,   ³   s    	c          @ s=   t  j j d ƒ s! t d ƒ ‚ n  t ƒ  ‰  ‡  f d †  }  |  S(   s4   
    Adds the Numba break point into the source
    R   s   gdb is only available on linuxc           @ s   ˆ  ƒ  d  S(   N(    (    (   t   bp_impl(    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyR+   É   s    (   R   t   platformt
   startswithR   t   gen_bp_impl(   R+   (    (   R‚   s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   hook_gdb_breakpointÀ   s
    	c          C@ s   t  d „  ƒ }  |  S(   Nc         S@ s   t  j ƒ  } d „  } | | f S(   Nc         S@ s\   | j  } t j t j ƒ  t ƒ  ƒ } | j | d ƒ } | j | t ƒ  ƒ |  j t j	 d  ƒ S(   NR:   (   RA   R   RG   RJ   RH   RI   RK   R{   R   R|   RU   (   RW   RX   RY   R)   Ra   Rj   Rk   (    (    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyR}   Ó   s    			(   R   R~   (   R   R€   R}   (    (    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   bp_internalÏ   s    	(   R   (   R‡   (    (    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyR…   Î   s    ("   t
   __future__R    R   R   R   t   llvmliteR   t   numbaR   R   R   R   R   R   R	   t   numba.extendingR
   R   R   t   dirnamet   __file__RE   Rƒ   t	   _platformR„   R   R(   R.   R0   R/   Rz   R,   R†   R…   (    (    (    s5   lib/python2.7/site-packages/numba/targets/gdb_hook.pyt   <module>   s"   4		"
i	