a
    ·Df                     @   s<   d Z ddlmZmZ ddlZddlZddlmZ dd ZdS )zMiscellaneous inspection tools
    )NamedTemporaryFileTemporaryDirectoryN)NumbaWarningc                    sT   zddl W n ty&   tdY n0 d fdd	G fdddt}| S )	z
    Gets the CFG of the disassembly of an ELF object, elf, at mangled name,
    mangled_symbol, and renders it appropriately depending on the execution
    environment (terminal/notebook).
    r   Nz$r2pipe package needed for disasm CFGc                    s  ddl m} | d u rtdt }td|d"}|  |  W d    n1 sZ0    Y  d}zDtj	|j
 d}tj||}| }|||j
f |}d}W nD ty }	 z,d|	 d	}
tt|
 |j
}W Y d }	~	n
d }	~	0 0 zrg d
}j||d}|d |rLd d }|d |d| d |d |d|  }|  W nF ty }	 z,dt|	v rd}
t|
n|	W Y d }	~	n
d }	~	0 0 W d    n1 s0    Y  |S )Nr   )	ToolchainzNo command givenF)deletedirz.soTzALinking the ELF object with the distutils toolchain failed with: z\. Disassembly will still work but might be less accurate and will not use DWARF information.)z-2z-e io.cache=truez-e scr.color=1z-e asm.dwarf=truez-e scr.utf8=true)flagsZaaaaaa=   ze bin.demangle=falsezs `is~ z[1]`ze bin.demangle=truez%szradare2 in PATHzThis feature requires 'radare2' to be installed and available on the system see: https://github.com/radareorg/radare2. Cannot find 'radare2' in $PATH.)Znumba.pycc.platformr   
ValueErrorr   r   writeflushospathbasenamenamejoinZlink_shared	Exceptionwarningswarnr   opencmdquitstrRuntimeError)r   r   tmpdirfZlinkedZraw_dso_nameZ
linked_dsoZtcZobj_to_analyseemsgr   rZmangled_symbol_61chardata)elfmangled_symbolr2pipe b/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/numba/misc/inspection.pyget_rendering   sL    

&



:z-disassemble_elf_to_cfg.<locals>.get_renderingc                       s$   e Zd Z fddZ fddZdS )z)disassemble_elf_to_cfg.<locals>.DisasmCFGc                    sX   zdd l }W n ty&   tdY n0  dd}|dd ||}|ddS )	Nr   z&graphviz package needed for disasm CFGZagfdr   zfontname="Courier",zfontname="Courier",fontsize=6,svgzUTF-8)graphvizImportErrorr   replaceZSourcepipedecode)selfr(   Zjupyter_renderingsrcr%   r#   r$   
_repr_svg_X   s    

z4disassemble_elf_to_cfg.<locals>.DisasmCFG._repr_svg_c                    s
    ddS )NZagfr&   r#   )r-   r/   r#   r$   __repr__d   s    z2disassemble_elf_to_cfg.<locals>.DisasmCFG.__repr__N)__name__
__module____qualname__r0   r1   r#   r/   r#   r$   	DisasmCFGV   s   r5   )N)r"   r)   r   object)r    r!   r5   r#   )r    r%   r!   r"   r$   disassemble_elf_to_cfg
   s    Ar7   )	__doc__tempfiler   r   r   r   Znumba.core.errorsr   r7   r#   r#   r#   r$   <module>   s
   