Ë
    ÖùdP=  ã                   ó€   — d dl mZmZ d dlZddlmZ ddlmZmZm	Z	 ddl
mZ ddlmZmZ  ed	d
«      Z G d„ de«      Zy)é    )Ú
namedtupleÚOrderedDictNé   )Ú
DWARFError)Ú	bytes2strÚstruct_parseÚpreserve_stream_posé   )ÚDW_FORM_raw2name)Ú_resolve_via_offset_tableÚ_get_base_offsetÚAttributeValuez3name form value raw_value offset indirection_lengthc                   ój   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚDIEa�   A DWARF debugging information entry. On creation, parses itself from
        the stream. Each DIE is held by a CU.

        Accessible attributes:

            tag:
                The DIE tag

            size:
                The size this DIE occupies in the section

            offset:
                The offset of this DIE in the stream

            attributes:
                An ordered dictionary mapping attribute names to values. It's
                ordered to preserve the order of attributes in the section

            has_children:
                Specifies whether this DIE has children

            abbrev_code:
                The abbreviation code pointing to an abbreviation entry (note
                that this is for informational purposes only - this object
                interacts with its abbreviation table transparently).

        See also the public methods.
    c                 óö   — || _         | j                   j                  | _        || _        || _        t	        «       | _        d| _        d| _        d| _        d| _	        d| _
        d| _        | j                  «        y)a   cu:
                CompileUnit object this DIE belongs to. Used to obtain context
                information (structs, abbrev table, etc.)

            stream, offset:
                The stream and offset into it where this DIE's data is located
        Nr   )ÚcuÚ	dwarfinfoÚstreamÚoffsetr   Ú
attributesÚtagÚhas_childrenÚabbrev_codeÚsizeÚ_terminatorÚ_parentÚ
_parse_DIE)Úselfr   r   r   s       ú4/usr/lib/python3/dist-packages/elftools/dwarf/die.pyÚ__init__zDIE.__init__K   sl   € ð ˆŒØŸ™×*Ñ*ˆŒØˆŒØˆŒä%›-ˆŒØˆŒØ ˆÔØˆÔØˆŒ	ð  ˆÔØˆŒà�‰Õó    c                 ó   — | j                   du S )z Is this a null entry?
        N)r   ©r   s    r   Úis_nullzDIE.is_nulld   s   € ð �x‰x˜4ÐÐr!   c                 óp  — | j                   |   }|j                  dv r>| j                  j                  |j                  z   }| j                  j                  |«      S |j                  dv r/| j                  j                  j                  |j                  «      S |j                  dv rt        d|j                  z  «      ‚|j                  dv r]| j                  j                  r/| j                  j                  j                  |j                  «      S t        d|j                  z  «      ‚t        d|z  «      ‚)zà Return the DIE referenced by the named attribute of this DIE.
            The attribute must be in the reference attribute class.

            name:
                The name of the attribute in the reference class.
        )ÚDW_FORM_ref1ÚDW_FORM_ref2ÚDW_FORM_ref4ÚDW_FORM_ref8ÚDW_FORM_refÚDW_FORM_ref_udataÚDW_FORM_ref_addrÚDW_FORM_ref_sig8z%s (type unit by signature))ÚDW_FORM_ref_sup4ÚDW_FORM_ref_sup8ÚDW_FORM_GNU_ref_altz	%s to dwoz*%s is not a reference class form attribute)
r   Úformr   Ú	cu_offsetÚ	raw_valueÚget_DIE_from_refaddrr   ÚNotImplementedErrorÚsupplementary_dwarfinfor   )r   ÚnameÚattrÚrefaddrs       r   Úget_DIE_from_attributezDIE.get_DIE_from_attributei   s  € ð �‰˜tÑ$ˆØ�9‰9ð Mñ Mà—g‘g×'Ñ'¨$¯.©.Ñ8ˆGØ—7‘7×/Ñ/°Ó8Ð8Ø�Y‰YÐ-Ñ.Ø—7‘7×$Ñ$×9Ñ9¸$¿.¹.ÓIÐIØ�Y‰YÐ-Ñ.ä%Ð&CÀdÇiÁiÑ&OÓPÐPØ�Y‰YÐYÑYØ�~‰~×5Ò5Ø—~‘~×=Ñ=×RÑRÐSW×SaÑSaÓbÐbä% k°D·I±IÑ&=Ó>Ð>äÐIÈDÑPÓQÐQr!   c                 óR   — | j                   €| j                  «        | j                   S )zt Return the parent DIE of this DIE, or None if the DIE has no
            parent (i.e. is a top-level DIE).
        )r   Ú_search_ancestor_offspringr#   s    r   Ú
get_parentzDIE.get_parent‚   s$   € ð �<‰<ÐØ×+Ñ+Ô-Ø�|‰|Ðr!   c                 ó  — | j                   j                  dd«      }|rt        |j                  «      nd}| j                   j                  dd«      }|rt        |j                  «      nd}t        j
                  j                  ||«      S )aF   Return the full path filename for the DIE.

            The filename is the join of 'DW_AT_comp_dir' and 'DW_AT_name',
            either of which may be missing in practice. Note that its value is
            usually a string taken from the .debug_string section and the
            returned value will be a string.
        ÚDW_AT_comp_dirNÚ Ú
DW_AT_name)r   Úgetr   ÚvalueÚosÚpathÚjoin)r   Úcomp_dir_attrÚcomp_dirÚ
fname_attrÚfnames        r   Úget_full_pathzDIE.get_full_pathŠ   sn   € ð Ÿ™×+Ñ+Ð,<¸dÓCˆÙ5B”9˜]×0Ñ0Ô1ÈˆØ—_‘_×(Ñ(¨°tÓ<ˆ
Ù/9”	˜*×*Ñ*Ô+¸rˆÜ�w‰w�|‰|˜H eÓ,Ð,r!   c                 ó8   — | j                   j                  | «      S )z+ Iterates all children of this DIE
        )r   Úiter_DIE_childrenr#   s    r   Úiter_childrenzDIE.iter_children˜   s   € ð �w‰w×(Ñ(¨Ó.Ð.r!   c              #   ó€   K  — | j                  «       }|r|j                  «       D ]  }|| usŒ|–— Œ yt        «       ‚­w)z( Yield all siblings of this DIE
        N)r=   rN   ÚStopIteration)r   ÚparentÚsiblings      r   Úiter_siblingszDIE.iter_siblings�   sF   è ø€ ð —‘Ó"ˆÙØ!×/Ñ/Ó1ò "�Ø $Ò&Ø!“Mñ"ô  “/Ð!ùs   ‚*>­>c                 ó   — || _         y ©N)r   )r   Údies     r   Ú
set_parentzDIE.set_parent¬   s	   € Øˆ�r!   c                 ó
  — | j                   j                  «       }|j                  | j                  k  rÐ|}|j                  «       D ]/  }|j	                  |«       |j                  | j                  k  sŒ.|}Œ1 |j
                  r/|j                  j                  | j                  k  r|j                  }||u r0t        d| j                  ›d| j                   j                  ›d�«      ‚|}|j                  | j                  k  rŒÏyy)aŸ   Search our ancestors identifying their offspring to find our parent.

            DIEs are stored as a flattened tree.  The top DIE is the ancestor
            of all DIEs in the unit.  Each parent is guaranteed to be at
            an offset less than their children.  In each generation of children
            the sibling with the closest offset not greater than our offset is
            our ancestor.
        zoffset z not in CU z	 DIE treeN)	r   Úget_top_DIEr   rN   rW   r   r   Ú
ValueErrorr2   )r   ÚsearchÚprevÚchilds       r   r<   zDIE._search_ancestor_offspring±   sÚ   € ð —‘×$Ñ$Ó&ˆØ�m‰m˜dŸk™kÒ)ØˆDØ×-Ñ-Ó/ò !�Ø× Ñ  Ô(Ø—<‘< 4§;¡;Ó.Ø ‘Dð!ð ×"Ò" v×'9Ñ'9×'@Ñ'@ÀDÇKÁKÒ'OØ!×-Ñ-�Dð
 �v‰~Ý Ø—[“[ $§'¡'×"3Ó"3ð"5ó 6ð 6ð ˆFð% �m‰m˜dŸk™kÕ)r!   c                 ó¸   — d| j                   ›d| j                  ›d| j                  ›d�}| j                  j	                  «       D ]  \  }}|d|d›d|›d�z  }Œ |S )NzDIE z, size=z, has_children=ú
z    |Ú18z:  )r   r   r   r   Úitems)r   ÚsÚattrnameÚattrvals       r   Ú__repr__zDIE.__repr__Õ   sS   � à�H‹H�d—i“i ×!2Ó!2ð4ˆà!%§¡×!6Ñ!6Ó!8ò 	;ÑˆH�gÙ«²'Ð:Ñ:‰Að	;àˆr!   c                 ó"   — | j                  «       S rU   )re   r#   s    r   Ú__str__zDIE.__str__Ü   s   € Ø�}‰}‹Ðr!   c           	      ó°  — | j                   j                  }t        |j                  d«      | j                  | j
                  «      | _        | j                  dk(  r-| j                  j                  «       | j
                  z
  | _        y| j                   j                  «       j                  | j                  «      }|d   | _        |j                  «       | _        |d   D ]É  }|j                  }|j                  }| j                  j                  «       }d}|dk(  r|j                  }|}	na|dk(  r'| j!                  «       \  }}	}| j#                  ||	«      }n5t        |j$                  |   | j                  «      }	| j#                  ||	«      }t'        ||||	||¬«      | j(                  |<   ŒË | j                  j                  «       | j
                  z
  | _        y)	ze Parses the DIE info from the section, based on the abbreviation
            table of the CU
        r@   r   Nr   Ú	attr_specÚDW_FORM_implicit_constÚDW_FORM_indirect©r7   r1   rC   r3   r   Úindirection_length)r   Ústructsr   ÚDwarf_uleb128r   r   r   Útellr   Úget_abbrev_tableÚ
get_abbrevr   r   r1   r7   rC   Ú_resolve_indirectÚ_translate_attr_valueÚDwarf_dw_formr   r   )
r   rn   Úabbrev_declÚspecr1   r7   Úattr_offsetrm   rC   r3   s
             r   r   zDIE._parse_DIEß   s¦  € ð —'‘'—/‘/ˆô (Ø×!Ñ! "Ó% t§{¡{°D·K±KóAˆÔð ×Ñ˜qÒ ØŸ™×(Ñ(Ó*¨T¯[©[Ñ8ˆDŒIØà—g‘g×.Ñ.Ó0×;Ñ;¸D×<LÑ<LÓMˆØ˜uÑ%ˆŒØ'×4Ñ4Ó6ˆÔð   Ñ,ò 	9ˆDØ—9‘9ˆDØ—9‘9ˆDØŸ+™+×*Ñ*Ó,ˆKØ!"Ðð Ð/Ò/ØŸ
™
�Ø!‘	àÐ+Ò+Ø8<×8NÑ8NÓ8PÑ5��yÐ"4Ø×2Ñ2°4¸ÓC‘ä(¨×)>Ñ)>¸tÑ)DÀdÇkÁkÓR�	Ø×2Ñ2°4¸ÓC�Ü$2ØØØØ#Ø"Ø%7ô%9ˆD�O‰O˜DÒ!ð#	9ð2 —K‘K×$Ñ$Ó&¨¯©Ñ4ˆ�	r!   c                 ó:  — | j                   j                  }d}t        |j                  d«      | j                  «      }	 	 t
        |   }t        |j                  |   | j                  «      }|dk7  r|||fS |dz  }|}Œ?# t        $ r}t        d|z  «      ‚d }~ww xY w)Nr
   r@   z2Found DW_FORM_indirect with unknown real form 0x%xrk   )	r   rn   r   ro   r   r   ÚKeyErrorr   ru   )r   rn   ÚlengthÚreal_form_codeÚ	real_formÚerrr3   s          r   rs   zDIE._resolve_indirect  s°   € ð —'‘'—/‘/ˆØˆÜ% g×&;Ñ&;¸BÓ&?ÀÇÁÓMˆØðhÜ,¨^Ñ<�	ô % W×%:Ñ%:¸9Ñ%EÀtÇ{Á{ÓSˆIàÐ.Ò.Ø! 9¨fÐ5Ð5à˜!‘�Ø!*�ð øô ò hÜ Ð!UÐXfÑ!fÓgÐgûðhús   Á 	A> Á>	BÂBÂBc                 óŠ  — | j                   j                  «       xs# | j                  | j                   j                  k7  }d}|dk(  r;t	        | j
                  «      5  | j                  j                  |«      }ddd«       |S |dk(  r;t	        | j
                  «      5  | j                  j                  |«      }ddd«       |S |dv r?| j                  j                  r%| j                  j                  j                  |«      S |}|S |dk(  r|dk(   }|S |dk(  rd}|S |d	v r4|r2| j                   j                  j                  | j                   |«      }|S |d
v rÆ|rÄ| j                  j                  j
                  }t        | j                   d«      }| j                   j                  j                  dk(  rdnd}t	        |«      5  t        | j                   j                  j!                  d«      ||||z  z   «      }ddd«       | j                  j                  «      }|S |dk(  r:|r8t#        | j                  j$                  j
                  | j                   |d«      }|S |dk(  r:|r8t#        | j                  j&                  j
                  | j                   |d«      }|S |}|S # 1 sw Y   |S xY w# 1 sw Y   |S xY w# 1 sw Y   ŒÂxY w)z: Translate a raw attr value according to the form
        NÚDW_FORM_strpÚDW_FORM_line_strp)ÚDW_FORM_GNU_strp_altÚDW_FORM_strp_supÚDW_FORM_flagr   ÚDW_FORM_flag_presentT)ÚDW_FORM_addrxÚDW_FORM_addrx1ÚDW_FORM_addrx2ÚDW_FORM_addrx3ÚDW_FORM_addrx4)ÚDW_FORM_strxÚDW_FORM_strx1ÚDW_FORM_strx2ÚDW_FORM_strx3ÚDW_FORM_strx4ÚDW_AT_str_offsets_baseé    é   é   r@   ÚDW_FORM_loclistxÚDW_AT_loclists_baseÚDW_FORM_rnglistxÚDW_AT_rnglists_base)r   Úhas_top_DIEr   Úcu_die_offsetr	   r   r   Úget_string_from_tableÚget_string_from_linetabler6   Úget_addrÚdebug_str_offsets_secr   rn   Údwarf_formatr   ÚDwarf_offsetr   Údebug_loclists_secÚdebug_rnglists_sec)	r   r1   r3   Útranslate_indirectrC   r   Úbase_offsetÚoffset_sizeÚ
str_offsets	            r   rt   zDIE._translate_attr_value)  sÊ  € ð "ŸW™W×0Ñ0Ó2ÒZ°d·k±kÀTÇWÁW×EZÑEZÑ6ZÐØˆØ�>Ò!Ü$ T§[¡[Ó1ñ HØŸ™×<Ñ<¸YÓG�÷Hð: ˆð7 Ð(Ò(Ü$ T§[¡[Ó1ñ LØŸ™×@Ñ@ÀÓK�÷Lð4 ˆð1 ÐAÑAØ�~‰~×5Ò5Ø—~‘~×=Ñ=×SÑSÐT]Ó^Ð^à!�ð( ˆð' �^Ò#Ø! Q™Ð&ˆEð$ ˆð# Ð+Ò+ØˆEð  ˆð ÐnÑnñ  tFØ—G‘G×%Ñ%×.Ñ.¨t¯w©w¸	ÓBˆEð ˆð ÐiÑiñ  oAØ—^‘^×9Ñ9×@Ñ@ˆFÜ*¨4¯7©7Ð4LÓMˆKØ#Ÿw™wŸ™×;Ñ;¸rÒA™!ÀqˆKÜ$ VÓ,ñ yÜ)¨$¯'©'¯/©/×*FÑ*FÀrÓ*JÈFÐT_ÐbkÐlwÑbwÑTwÓx�
÷yà—N‘N×8Ñ8¸ÓDˆEð ˆð Ð'Ò'Ñ,>Ü-¨d¯n©n×.OÑ.O×.VÑ.VÐX\×X_ÑX_Ðajð  mBó  CˆEð
 ˆð	 Ð'Ò'Ñ,>Ü-¨d¯n©n×.OÑ.O×.VÑ.VÐX\×X_ÑX_Ðajð  mBó  CˆEð ˆð ˆEØˆ÷;Hð: ˆú÷5Lð4 ˆú÷yð yús$   ÁJÂJ,Ç7J9ÊJ)Ê,J6Ê9Kc           	      óJ  — | j                   D ]”  }| j                   |   }|j                  dv sŒ!t        |j                  |j                  | j	                  |j                  |j
                  «      |j
                  |j                  |j                  ¬«      | j                   |<   Œ– y)a\   This is a hook to translate the DW_FORM_...x values in the top DIE
            once the top DIE is parsed to the end. They can't be translated 
            while the top DIE is being parsed, because they implicitly make a
            reference to the DW_AT_xxx_base attribute in the same DIE that may
            not have been parsed yet.
        )r‹   rŒ   r�   rŽ   r�   r†   r‡   rˆ   r‰   rŠ   r”   r–   rl   N)r   r1   r   r7   rt   r3   r   rm   )r   Úkeyr8   s      r   Ú_translate_indirect_attributesz"DIE._translate_indirect_attributesS  s‹   € ð —?‘?ò 	@ˆCØ—?‘? 3Ñ'ˆDØ�y‰yð 8ò 8ô (6ØŸ™ØŸ™Ø×4Ñ4°T·Y±YÀÇÁÓOØ"Ÿn™nØŸ;™;Ø'+×'>Ñ'>ô(@�—‘ Ò$ñ	@r!   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    r$   r:   r=   rK   rN   rS   rW   r<   re   rg   r   rs   rt   r¨   © r!   r   r   r   .   sW   „ ñò8ò2 ò
Rò2ò-ò/ò
	"òò
"òHòò15òf+ò.(óT@r!   r   )Úcollectionsr   r   rD   Úcommon.exceptionsr   Úcommon.utilsr   r   r	   Úenumsr   Ú
dwarf_utilr   r   r   Úobjectr   r­   r!   r   ú<module>r´      s?   ð÷ 0Û 	å *ß GÑ GÝ #ß Cñ6 ØÐKóM€ôx@ˆ&õ x@r!   