o
    $ôj“  ã                   @   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                    sP   zddl ‰W n ty   tdƒ‚w 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 s,w   Y  d}z"tj 	|j
¡› d�}tj ||¡}|ƒ }| ||j
f¡ |}d}W n" tyw }	 zd|	› d	�}
t t|
ƒ¡ |j
}W Y d }	~	nd }	~	ww z8g d
¢}ˆj||d�}| d¡ |r¤ˆd d… }| d¡ | d|› d�¡ | d¡ | d|  ¡}| ¡  W n tyÊ }	 zdt|	ƒv rÄd}
t|
ƒ‚|	‚d }	~	ww W d   ƒ |S 1 sÖw   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 PATHz–This 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_dsoÚtcZobj_to_analyseÚeÚmsgr   ÚrZmangled_symbol_61charÚdata)ÚelfÚmangled_symbolÚr2pipe© úh/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/numba/misc/inspection.pyÚget_rendering   s^   

þÿ€÷


€øÿ
Ð:Æ: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                    sT   zdd l }W n ty   tdƒ‚w ˆ 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   ÚreplaceÚ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/   r1   r$   r%   Ú__repr__d   s   
z2disassemble_elf_to_cfg.<locals>.DisasmCFG.__repr__N)Ú__name__Ú
__module__Ú__qualname__r2   r3   r$   r1   r$   r%   Ú	DisasmCFGV   s    r7   )N)r#   r*   r   Úobject)r!   r"   r7   r$   )r!   r&   r"   r#   r%   Údisassemble_elf_to_cfg
   s   ÿAr9   )	Ú__doc__Útempfiler   r   r   r   Únumba.core.errorsr   r9   r$   r$   r$   r%   Ú<module>   s    