Ë
    ÖùdÞ  ã                   ó„   — d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	 ddl
mZmZmZ  G d„ de«      Z G d	„ d
e	«      Zy)z$
Debugging utilities for constructs
é    )Úprint_functionNé   )Ú	ConstructÚSubconstruct)Ú	HexStringÚ	ContainerÚListContainerc                   óH   — e Zd ZdZg d¢ZdZ	 	 	 dd„Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zy)ÚProbea¤  
    A probe: dumps the context, stack frames, and stream content to the screen
    to aid the debugging process.
    See also Debugger.

    Parameters:
    * name - the display name
    * show_stream - whether or not to show stream contents. default is True.
      the stream must be seekable.
    * show_context - whether or not to show the context. default is True.
    * show_stack - whether or not to show the upper stack frames. default
      is True.
    * stream_lookahead - the number of bytes to dump when show_stack is set.
      default is 100.

    Example:
    Struct("foo",
        UBInt8("a"),
        Probe("between a and b"),
        UBInt8("b"),
    )
    )Ú	printnameÚshow_streamÚshow_contextÚ
show_stackÚstream_lookaheadr   Nc                 óÔ   — t        j                  | d «       |€-t        xj                  dz  c_        dt        j                  fz  }|| _        || _        || _        || _        || _        y )Nr   z<unnamed %d>)	r   Ú__init__r   Úcounterr   r   r   r   r   )ÚselfÚnamer   r   r   r   s         ú:/usr/lib/python3/dist-packages/elftools/construct/debug.pyr   zProbe.__init__*   s^   € ô 	×Ñ˜4 Ô&Øˆ<Ü�MŠM˜QÑ�MØ!¤U§]¡]Ð$4Ñ4ˆDØˆŒØ&ˆÔØ(ˆÔØ$ˆŒØ 0ˆÕó    c                 óN   — | j                   j                  ›d| j                  ›d�S )Nú(ú))Ú	__class__Ú__name__r   )r   s    r   Ú__repr__zProbe.__repr__6   s   € ØŸ>™>×2Ó2°D·N³NÐCÐCr   c                 ó(   — | j                  ||«       y ©N©Úprintout©r   ÚstreamÚcontexts      r   Ú_parsezProbe._parse8   ó   € Ø�‰�f˜gÕ&r   c                 ó(   — | j                  ||«       y r   r    ©r   Úobjr#   r$   s       r   Ú_buildzProbe._build:   r&   r   c                  ó   — y)Nr   © )r   r$   s     r   Ú_sizeofzProbe._sizeof<   s   € Ør   c                 óÚ  — t        «       }| j                  rl|j                  «       |_        |j	                  | j
                  «      }|sd|_        n,|j                  t        |«       d«       t        |«      |_        t         | j                  r||_        | j                  rŽt        «       |_        t!        j                  «       D �cg c]  }|d   ‘Œ	 c}dd }|j#                  «        |D ]B  }t        «       }|j%                  |j&                  «       |j                  j)                  |«       ŒD t        d«       t        d| j*                  «       t        |«       t        d«       y c c}w )NzEOF reachedr   r   éÿÿÿÿúP================================================================================r   )r   r   ÚtellÚstream_positionÚreadr   Úfollowing_stream_dataÚseekÚlenr   Úprintr   r$   r   r	   ÚstackÚinspectÚreverseÚ
__update__Úf_localsÚappendr   )	r   r#   r$   r)   ÚfollowsÚsÚframesÚfÚas	            r   r!   zProbe.printout?   s  € Ü‹kˆØ×ÒØ"(§+¡+£-ˆCÔØ—k‘k $×"7Ñ"7Ó8ˆGÙØ,9�Õ)à—‘œS ›\˜M¨1Ô-Ü,5°gÓ,>�Ô)Ýà×ÒØ!ˆCŒKà�?Š?Ü%›ˆCŒIÜ$+§M¡M£OÖ4˜q�a˜“dÒ4°Q°rÐ:ˆFØ�N‰NÔØò $�Ü“K�Ø—‘˜QŸZ™ZÔ(Ø—	‘	× Ñ  Õ#ð$ô
 	ˆhŒÜˆg�t—~‘~Ô&ÜˆcŒ
Üˆh�ùò 5s   ÃE()NTTTéd   )r   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r%   r*   r-   r!   r,   r   r   r   r      s=   „ ñò,€Ið €Gà26Ø37Ø$'ó1òDò'ò'òór   r   c                   ó*   — e Zd ZdZdgZd„ Zd„ Zdd„Zy)ÚDebuggeraR  
    A pdb-based debugger. When an exception occurs in the subcon, a debugger
    will appear and allow you to debug the error (and even fix on-the-fly).

    Parameters:
    * subcon - the subcon to debug

    Example:
    Debugger(
        Enum(UBInt8("foo"),
            a = 1,
            b = 2,
            c = 3
        )
    )
    Úretvalc                 óÐ   — 	 | j                   j                  ||«      S # t        $ r> t        | _        | j                  d«       | j                  t        u r‚ | j                  cY S w xY w)Nz@(you can set the value of 'self.retval', which will be returned))Úsubconr%   Ú	ExceptionÚNotImplementedrJ   Ú
handle_excr"   s      r   r%   zDebugger._parsen   s^   € ð		#Ø—;‘;×%Ñ% f¨gÓ6Ð6øÜò 	#Ü(ˆDŒKØ�O‰Oð *ô +à�{‰{œnÑ,Øà—{‘{Ò"ð	#ús   ‚ žAA%Á$A%c                 ó~   — 	 | j                   j                  |||«       y # t        $ r | j                  «        Y y w xY wr   )rL   r*   rM   rO   r(   s       r   r*   zDebugger._buildy   s6   € ð	Ø�K‰K×Ñ˜s F¨GÕ4øÜò 	Ø�O‰OÖð	ús   ‚   <»<Nc                 óN  — t        d«       t        d| j                  ›d�«       t        dj                  t        j                  t        j                  «       Ž dd  «      «       |rt        |«       t        j                  t        j                  «       d   «       t        d«       y )Nr0   zDebugging exception of ú:Ú r   é   )	r7   rL   ÚjoinÚ	tracebackÚformat_exceptionÚsysÚexc_infoÚpdbÚpost_mortem)r   Úmsgs     r   rO   zDebugger.handle_exc~   si   € ÜˆhŒÝ¨d¯k«kÐ;Ô<Üˆb�g‰g”i×0Ñ0´#·,±,³.ÐAÀ!À"ÐEÓFÔGÙÜ�#ŒJÜ�‰œŸ™› qÑ)Ô*Üˆh�r   r   )r   rD   rE   rF   rG   r%   r*   rO   r,   r   r   rI   rI   \   s   „ ñð  �
€Iò
#òô
r   rI   )rF   Ú
__future__r   rX   rV   rZ   r9   Úcorer   r   Úlibr   r   r	   r   rI   r,   r   r   ú<module>r`      s?   ðñõ &Û 
Û Û 
Û ß )ß 4Ñ 4ôMˆIô Mô^)ˆ|õ )r   