
    d/%                     >    d dl mZ ddlmZ ddlmZ  G d de      Zy)	    )bisect_right   )DIE   )dwarf_assertc                   b    e Zd ZdZd Zd Zd Zd Zd Ze	d        Z
d Zd	 Zd
 Zd Zd Zd Zy)CompileUnita   A DWARF compilation unit (CU).

            A normal compilation unit typically represents the text and data
            contributed to an executable by a single relocatable object file.
            It may be derived from several source files,
            including pre-processed "include files"

        Serves as a container and context to DIEs that describe objects and code
        belonging to a compilation unit.

        CU header entries can be accessed as dict keys from this object, i.e.
           cu = CompileUnit(...)
           cu['version']  # version field of the CU header

        To get the top-level DIE describing the compilation unit, call the
        get_top_DIE method.
    c                 t    || _         || _        || _        || _        || _        d| _        g | _        g | _        y)a   header:
                CU header for this compile unit

            dwarfinfo:
                The DWARFInfo context object which created this one

            structs:
                A DWARFStructs instance suitable for this compile unit

            cu_offset:
                Offset in the stream to the beginning of this CU (its header)

            cu_die_offset:
                Offset in the stream of the top DIE of this CU
        N)	dwarfinfoheaderstructs	cu_offsetcu_die_offset_abbrev_table_dielist_diemap)selfr   r   r   r   r   s         </usr/lib/python3/dist-packages/elftools/dwarf/compileunit.py__init__zCompileUnit.__init__    sD      #"* "      c                 .    | j                   j                  S )z5 Get the DWARF format (32 or 64) for this CU
        )r   dwarf_formatr   s    r   r   zCompileUnit.dwarf_formatE   s     ||(((r   c                 x    | j                   #| j                  j                  | d         | _         | j                   S )zE Get the abbreviation table (AbbrevTable object) for this CU
        debug_abbrev_offset)r   r   get_abbrev_tabler   s    r   r   zCompileUnit.get_abbrev_tableJ   s<     %!%!@!@*+"-D!!!r   c                 d   t        | j                        dkD  r| j                  d   S t        | | j                  j
                  j                  | j                        }| j                  j                  d|       | j                  j                  d| j                         |j                          |S )zo Get the top DIE (which is either a DW_TAG_compile_unit or
            DW_TAG_partial_unit) of this CU
        r   custreamoffset)
lenr   r   r   r   debug_info_secr    r   insert_translate_indirect_attributes)r   tops     r   get_top_DIEzCompileUnit.get_top_DIER   s     t||q ==##~~44;;))+
 	Q$At112**,
r   c                 2    t        | j                        dkD  S )zv Returns whether the top DIE in this CU has already been parsed and cached.
            No parsing on demand!
        r   )r"   r   r   s    r   has_top_DIEzCompileUnit.has_top_DIEh   s     4<< 1$$r   c                 B    | d   | j                   j                         z   S )Nunit_length)r   initial_length_field_sizer   s    r   sizezCompileUnit.sizen   s    M"T\\%K%K%MMMr   c                     t        | j                  |cxk  xr | j                  | j                  z   k  nc d|d| j                         | j	                  |      S )a   Obtain a DIE contained in this CU from a reference.

            refaddr:
                The offset into the .debug_info section, which must be
                contained in this CU or a DWARFError will be raised.

            When using a reference class attribute with a form that is
            relative to the compile unit, add unit add the compile unit's
            .cu_addr before calling this function.
        zrefaddr z not in DIE range of CU )r   r   r   r-   _get_cached_DIE)r   refaddrs     r   get_DIE_from_refaddrz CompileUnit.get_DIE_from_refaddrr   sM     	'FDNNTYY,FF6=t~~N	P ##G,,r   c                 @    | j                  | j                               S )z Iterate over all the DIEs in the CU, in order of their appearance.
            Note that null DIEs will also be returned.
        )_iter_DIE_subtreer'   r   s    r   	iter_DIEszCompileUnit.iter_DIEs   s     %%d&6&6&899r   c              #     K   |j                   sy|j                  |j                  z   }	 | j                  |      }|j	                  |       |j                         r||_        y| |j                   s||j                  z  }nd|j                  v rk|j                  d   }|j                  dv r|j                  | j                  z   }n|j                  dk(  r|j                  }ngt        d|j                  z        |j                  | j                  |      D ]  } |j                  j                  |j                  j                  z   }$w)z Given a DIE, yields either its children, without null DIE list
            terminator, or nothing, if that DIE has no children.

            The null DIE terminator is saved in that DIE when iteration ended.
        NDW_AT_sibling)DW_FORM_ref1DW_FORM_ref2DW_FORM_ref4DW_FORM_ref8DW_FORM_refDW_FORM_ref_udataDW_FORM_ref_addrzsibling in form %s)has_childrenr!   r-   r/   
set_parentis_null_terminator
attributesformvaluer   NotImplementedErroriter_DIE_children)r   die
cur_offsetchildsibling_s         r   rF   zCompileUnit.iter_DIE_children   s=      ZZ#((*
((4ES!}}"'K%%ejj(
 E$4$44**?;<< $H H ")!?J\\%77!(J-.BW\\.QRR $$,!33E:  #..558I8I8N8NN
K s   EEc                      | j                   |   S )z6 Implement dict-like access to header entries
        )r   )r   names     r   __getitem__zCompileUnit.__getitem__   s     {{4  r   c              #   (  K   |j                   dk(  r'| j                  j                  r|j                  d      }| |j                  rH|j                         D ]&  }|j                  j                  |      D ]  }|  ( |j                   yyw)zp Given a DIE, this yields it with its subtree including null DIEs
            (child list terminators).
        DW_TAG_imported_unitDW_AT_importN)	tagr   supplementary_dwarfinfoget_DIE_from_attributer>   iter_childrenr   r3   rA   )r   rG   cds       r   r3   zCompileUnit._iter_DIE_subtree   s      77,,1W1W,,^<C	&&( 11!4 AG //!	 s   BBc                 D   | j                         j                  }t        | j                  |      }|| j                  |dz
     k(  r| j                  |dz
     }|S t        | ||      }| j                  j                  ||       | j                  j                  ||       |S )a   Given a DIE offset, look it up in the cache.  If not present,
            parse the DIE and insert it into the cache.

            offset:
                The offset of the DIE in the debug_info section to retrieve.

            The stream reference is copied from the top DIE.  The top die will
            also be parsed and cached if needed.

            See also get_DIE_from_refaddr(self, refaddr).
        r   r   )r'   r    r   r   r   r   r$   )r   r!   top_die_streamirG   s        r   r/   zCompileUnit._get_cached_DIE   s     ))+22 v.
 T\\!a%((--A&C 
	 nVDCMM  C(LL6*
r   N)__name__
__module____qualname____doc__r   r   r   r'   r)   propertyr-   r1   r4   rF   rN   r3   r/    r   r   r	   r	      sW    "#J)
",% N N-$:2Ol!
"!r   r	   N)bisectr   rG   r   common.utilsr   objectr	   r`   r   r   <module>rd      s       'g& gr   