Ë
    ÖùdEF  ã            	       óð   — d dl Z d dlmZ ddlmZ ddlmZ ddlmZ  edd	«      Z	 ed
d«      Z
 edd«      Z edd«      Zd„ Zd„ d„ d„ d„ d„ d„ d„ edœZ G d„ de«      Z G d„ de«      Z G d„ de«      Zy)é    N)Ú
namedtupleé   ©Ú
DWARFError)Ústruct_parseé   )Ú_iter_CUs_in_sectionÚLocationExprÚloc_exprÚLocationEntryzFentry_offset entry_length begin_offset end_offset loc_expr is_absoluteÚBaseAddressEntryz&entry_offset entry_length base_addressÚLocationViewPairzentry_offset begin endc                 óÄ   — |j                   j                  || j                  «      }t        | j                  | j
                  ||| j                  z   | j                  d«      S ©NT)Ú	dwarfinfoÚget_addrÚstart_indexr   Úentry_offsetÚentry_lengthÚlengthr   )ÚeÚcuÚstart_offsets      ú>/usr/lib/python3/dist-packages/elftools/dwarf/locationlists.pyÚ_translate_startx_lengthr      sM   € Ø—<‘<×(Ñ(¨¨Q¯]©]Ó;€LÜ˜Ÿ™¨¯©¸À|ÐVW×V^ÑV^ÑG^Ð`a×`jÑ`jÐlpÓqÐqó    c                 óX   — t        | j                  | j                  | j                  «      S ©N)r   r   r   Úaddress©r   r   s     r   ú<lambda>r!      s   € Ô-=¸a¿n¹nÈaÏnÉnÐ^_×^gÑ^gÓ-h€ r   c                 ó†   — t        | j                  | j                  | j                  | j                  | j
                  d«      S )NF)r   r   r   r   Ú
end_offsetr   r    s     r   r!   r!      sB   € ¬]¸1¿>¹>È1Ï>É>Ð[\×[iÑ[iÐkl×kwÑkwÐyz÷  zDñ  zDð  FKó  .L€ r   c                 ó    — t        | j                  | j                  | j                  | j                  | j                  z   | j
                  d«      S r   )r   r   r   Ústart_addressr   r   r    s     r   r!   r!      s^   € ¬]¸1¿>¹>È1Ï>É>Ð[\×[jÑ[jÐlm×l{Ñl{Ð~÷  Gñ  Gñ  mGð  IJ÷  ISñ  ISð  UYó  .Z€ r   c                 ó†   — t        | j                  | j                  | j                  | j                  | j
                  d«      S r   )r   r   r   r%   Úend_addressr   r    s     r   r!   r!      sB   € ¬]¸1¿>¹>È1Ï>É>Ð[\×[jÑ[jÐlm×lyÑlyÐ{|÷  |Fñ  |Fð  HLó  .M€ r   c                 ó^   — t        | j                  | j                  dd| j                  d«      S )NéÿÿÿÿT)r   r   r   r   r    s     r   r!   r!      s'   € ¬]¸1¿>¹>È1Ï>É>Ð[]Ð_aÐcd×cmÑcmÐosÓ-t€ r   c                 óŒ   — t        | j                  | j                  |j                  j	                  || j
                  «      «      S r   )r   r   r   r   r   Úindexr    s     r   r!   r!      s;   € Ô-=¸a¿n¹nÈaÏnÉnÐ^`×^jÑ^j×^sÑ^sÐtvÐxy×xÑxó  _Aó  .B€ r   c           	      óî   — t        | j                  | j                  |j                  j	                  || j
                  «      |j                  j	                  || j                  «      | j                  d«      S r   )r   r   r   r   r   r   Ú	end_indexr   r    s     r   r!   r!       s¤   € ¬]¸1¿>¹>È1Ï>É>Ð[]×[gÑ[g×[pÑ[pÐqsÐuv÷  vCñ  vCó  \Dð  FH÷  FRñ  FR÷  F[ñ  F[ð  \^ð  `a÷  `kñ  `kó  Flð  no÷  nxñ  nxð  z~ó  .€ r   )ÚDW_LLE_base_addressÚDW_LLE_offset_pairÚDW_LLE_start_lengthÚDW_LLE_start_endÚDW_LLE_default_locationÚDW_LLE_base_addressxÚDW_LLE_startx_endxÚDW_LLE_startx_lengthc                   ó,   — e Zd ZdZdd„Zdd„Zd„ Zd„ Zy)ÚLocationListsPairz©For those binaries that contain both a debug_loc and a debug_loclists section,
    it holds a LocationLists object for both and forwards API calls to the right one.
    Nc                 óP   — t        ||d|«      | _        t        ||d|«      | _        y )Né   é   )ÚLocationListsÚ_locÚ	_loclists)ÚselfÚstreamv4Ústreamv5Ústructsr   s        r   Ú__init__zLocationListsPair.__init__(   s&   € Ü! (¨G°Q¸	ÓBˆŒ	Ü& x°¸!¸YÓGˆ�r   c                 ó¶   — |€t        d«      ‚|j                  j                  j                  dk\  r| j                  n| j
                  }|j                  ||«      S )z9See LocationLists.get_location_list_at_offset().
        ú+For this binary, "die" needs to be providedr:   )r   r   ÚheaderÚversionr=   r<   Úget_location_list_at_offset)r>   ÚoffsetÚdieÚsections       r   rG   z-LocationListsPair.get_location_list_at_offset,   sL   € ð ˆ;ÜÐLÓMÐMØ$'§F¡F§M¡M×$9Ñ$9¸QÒ$>�$—.’.ÀDÇIÁIˆØ×2Ñ2°6¸3Ó?Ð?r   c                 ó   — t        d«      ‚)z›Tricky proposition, since the structure of loc and loclists
        is not identical. A realistic readelf implementation needs to be aware of both
        ú/Iterating through two sections is not supportedr   ©r>   s    r   Úiter_location_listsz%LocationListsPair.iter_location_lists4   s   € ô ÐJÓKÐKr   c                 ó   — t        d«      ‚)zTSee LocationLists.iter_CUs()

        There are no CUs in DWARFv4 sections.
        rL   r   rM   s    r   Úiter_CUszLocationListsPair.iter_CUs:   s   € ô
 ÐJÓKÐKr   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rB   rG   rN   rP   © r   r   r7   r7   $   s   „ ñóHó@òLóLr   r7   c                   óF   — e Zd ZdZdd„Zdd„Zd„ Zd„ Zd„ Zdd„Z	d	„ Z
d
„ Zy)r;   aè   A single location list is a Python list consisting of LocationEntry or
        BaseAddressEntry objects.

        Starting with DWARF5, it may also contain LocationViewPair, but only
        if scanning the section, never when requested for a DIE attribute.

        The default location entries are returned as LocationEntry with
        begin_offset == end_offset == -1

        Version determines whether the executable contains a debug_loc
        section, or a DWARFv5 style debug_loclists one. Only the 4/5
        distinction matters.

        Dwarfinfo is only needed for DWARFv5 location entry encodings
        that contain references to other sections (e. g. DW_LLE_startx_endx),
        and only for location list enumeration.
    Nc                 ó„   — || _         || _        || _        || _        d| j                  j                  dz  z  dz
  | _        y )Nr   é   r   )ÚstreamrA   r   rF   Úaddress_sizeÚ	_max_addr)r>   rY   rA   rF   r   s        r   rB   zLocationLists.__init__S   s>   € ØˆŒØˆŒØ"ˆŒØˆŒØ˜tŸ|™|×8Ñ8¸1Ñ<Ñ=ÀÑAˆ�r   c                 ó  — | j                   dk\  r|€t        d«      ‚| j                  j                  |t        j
                  «       | j                   dk\  r| j                  |j                  «      S | j                  «       S )zÑ Get a location list at the given offset in the section.
        Passing the die is only neccessary in DWARF5+, for decoding
        location entry encodings that contain references to other sections.
        r:   rD   )	rF   r   rY   ÚseekÚosÚSEEK_SETÚ#_parse_location_list_from_stream_v5r   Ú _parse_location_list_from_stream)r>   rH   rI   s      r   rG   z)LocationLists.get_location_list_at_offsetZ   sr   € ð
 �<‰<˜1Ò  ÜÐLÓMÐMØ�‰×Ñ˜¤§¡Ô-ØCGÇ<Á<ÐSTÒCTˆt×7Ñ7¸¿¹Ó?ð  	BÐZ^×ZÑZó  [Bð  	Br   c              #   ó@  K  — | j                   dk\  }| j                  }|j                  dt        j                  «       |j                  «       }|j                  dt        j                  «       t        «       }t        «       }t        «       }| j                  j                  «       D �]:  }|d   }|dk\  |k(  sŒ|j                  «       D �]  }	d|	j                  v r€d|	j                  v r#t        j                  |	j                  d   |«      sJ ‚|	j                  d   j                  }
|	j                  d   j                  }|||
<   |||<   |j!                  |
«       |	j                  D ]u  }|	j                  |   }|dk7  sd|	j                  vsŒ&t        j#                  ||«      sŒ=t        j                  ||«      sŒT|j                  }|j!                  |«       |||<   Œw �Œ �Œ= t%        |«      }|j'                  «        |�rd}|j                  «       |k  �rt)        | j*                  j,                  |«      }|j                   dk(  sJ ‚|j.                  |j0                  z   }|j                  «       |k  r“||   }||j                  «       k(  r@| j3                  |«      }| j5                  ||j                  «          «      }||z   –— |dz  }n'||kD  r|}|j                  |t        j                  «       |j                  «       |k  rŒ“|j                  «       |k  r�Œyy|D ]y  }|j7                  ||«      }||   j8                  j                   dk  sŒ2|j                  |t        j                  «       | j3                  |«      }| j;                  «       }||z   –— Œ{ y­w)z‘ Iterates through location lists and view pairs. Returns lists of
        LocationEntry, BaseAddressEntry, and LocationViewPair objects.
        r:   r   rF   ÚDW_AT_GNU_locviewsÚDW_AT_locationr   N)rF   rY   r]   r^   ÚSEEK_ENDÚtellr_   ÚsetÚdictr   rP   Ú	iter_DIEsÚ
attributesÚLocationParserÚ_attribute_has_loc_listÚvalueÚaddÚattribute_has_locationÚlistÚsortr   rA   ÚDwarf_loclists_CU_headerÚoffset_after_lengthÚunit_lengthÚ_parse_locview_pairsr`   ÚgetrE   ra   )r>   Úver5rY   ÚendposÚall_offsetsÚlocviewsÚcu_mapr   Úcu_verrI   Úviews_offsetÚlist_offsetÚkeyÚattrÚoffset_indexÚ	cu_headerÚcu_end_offsetÚnext_offsetÚlocview_pairsÚentriesrH   s                        r   rN   z!LocationLists.iter_location_listsd   sC  è ø€ ð$ �|‰|˜qÑ ˆØ—‘ˆØ�‰�A”r—{‘{Ô#Ø—‘“ˆà�‰�A”r—{‘{Ô#ô “eˆÜ“6ˆÜ“ˆØ—.‘.×)Ñ)Ó+ó 	5ˆBØ˜	‘]ˆFØ˜!‘ Ó$ØŸ<™<›>ó 5�Cð ,¨s¯~©~Ñ=Ø/°3·>±>ÑAÜ*×BÑBÀ3Ç>Á>ÐRbÑCcÐekÔlðnð  mà'*§~¡~Ð6JÑ'K×'QÑ'Q˜Ø&)§n¡nÐ5EÑ&F×&LÑ&L˜Ø1<˜ Ñ.Ø.0˜˜{Ñ+Ø#Ÿ™¨Ô5ð  #Ÿ~™~ò 5˜Ø"Ÿ~™~¨cÑ2˜Ø Ð$4Ò4Ð8LÐTW×TbÑTbÒ8bÜ*×AÑAÀ$ÈÕOÜ*×BÑBÀ4ÈÕPØ*.¯*©*˜KØ'ŸO™O¨KÔ8Ø24˜F ;Ò/ò5ò5ð	5ô0 ˜;Ó'ˆØ×ÑÔâð ˆLØ—+‘+“- &Ó(ä(¨¯©×)NÑ)NÐPVÓW�	Ø ×(Ñ(¨AÒ-Ð.Ð-ð !*× =Ñ =À	×@UÑ@UÑ U�ð —k‘k“m mÒ3à"-¨lÑ";�KØ" f§k¡k£mÒ3Ø(,×(AÑ(AÀ(Ó(K˜Ø"&×"JÑ"JÈ6ÐRX×R]ÑR]ÓR_ÑK`Ó"a˜Ø+¨gÑ5Ò5Ø$¨Ñ)™à&¨Ò6Ø*7˜KØŸ™ K´·±Ô=ð —k‘k“m mÓ3ð —+‘+“- &Ö(ð2 &ò 2�Ø&Ÿl™l¨6°6Ó:�Ø˜+Ñ&×-Ñ-×5Ñ5¸Ó9Ø—K‘K ¬¯©Ô4Ø$(×$=Ñ$=¸hÓ$G�MØ"×CÑCÓE�GØ'¨'Ñ1Ó1ñ2ùs3   ‚B5NÂ8CNÆNÆ#NÆ:ENÌNÌ5NÍANc                 óÒ   — | j                   dk  rt        d«      ‚t        | j                  j	                  «       «      j
                  }t        | j                  ||j                  «      S )zWFor DWARF5 returns an array of objects, where each one has an array of offsets
        r:   z6CU iteration in loclists is not supported with DWARF<5)	rF   r   Únextr   rP   rA   r	   rY   rr   )r>   rA   s     r   rP   zLocationLists.iter_CUsÂ   sR   € ð �<‰<˜!ÒÜÐUÓVÐVä�t—~‘~×.Ñ.Ó0Ó1×9Ñ9ˆÜ# D§K¡K°¸'×:ZÑ:ZÓ[Ð[r   c           
      ó  — g }	 | j                   j                  «       }t        | j                  j	                  d«      | j                   «      }t        | j                  j	                  d«      | j                   «      }|dk(  r|dk(  r	 |S || j
                  k(  r;| j                   j                  «       |z
  }|j                  t        |||¬«      «       n±t        | j                  j                  d«      | j                   «      }t        |«      D �cg c]1  }t        | j                  j                  d«      | j                   «      ‘Œ3 }}| j                   j                  «       |z
  }|j                  t        |||||d¬«      «       �Œ‚c c}w )NÚ r   )r   r   Úbase_addressF)r   r   Úbegin_offsetr#   r   Úis_absolute)rY   rf   r   rA   ÚDwarf_target_addrr[   Úappendr   ÚDwarf_uint16ÚrangeÚDwarf_uint8r   )	r>   Úlstr   rŒ   r#   r   Úexpr_lenÚir   s	            r   ra   z.LocationLists._parse_location_list_from_streamÍ   sd  € ØˆØØŸ;™;×+Ñ+Ó-ˆLÜ'Ø—‘×.Ñ.¨rÓ2°D·K±KóAˆLä%Ø—‘×.Ñ.¨rÓ2°D·K±KóAˆJà˜qÒ  Z°1¢_àð( ˆ
ð'  §¡Ò/à#Ÿ{™{×/Ñ/Ó1°LÑ@�Ø—
‘
Ô+¸ÐT`ÐoyÔzÕ{ô (Ø—L‘L×-Ñ-¨bÓ1°4·;±;ó@�ô */¨x«ö:à$%ô )¨¯©×)AÑ)AÀ"Ó)EØ)-¯©õ6ð :�ð :ð  $Ÿ{™{×/Ñ/Ó1°LÑ@�Ø—
‘
œ=Ø!-Ø!-Ø!-Ø)Ø%Ø"'ô)ô *ñ+ ùò":s   Ä6Fc                 óª   — t        | j                  j                  | j                  «      D �cg c]  }t	        |j
                     ||«      ‘Œ c}S c c}w )a   Returns an array with BaseAddressEntry and LocationEntry.
            No terminator entries.

            The cu argument is necessary if the section is a
            DWARFv5 debug_loclists one, and the target loclist
            contains indirect encodings.
        )r   rA   ÚDwarf_loclists_entriesrY   Úentry_translateÚ
entry_type)r>   r   Úentrys      r   r`   z1LocationLists._parse_location_list_from_stream_v5í   sO   € ô ˜DŸL™L×?Ñ?ÀÇÁÓMöOØô   × 0Ñ 0Ñ1°%¸Õ<ò Oð 	Oùò Os   ­ Ac                 óV  — |j                   }|j                  |z
  }|j                  }|dk(  rt        |||j                  «      S |dk(  r.t        |||j                  |j                  |j                  d«      S |dk(  r;t        |||j                  |j                  |j                  z   |j                  d«      S |dk(  r.t        |||j                  |j                  |j                  d«      S |dk(  rt        ||dd|j                  d«      S |d	v rt        d
|›d�«      ‚t        dd|›�«      ‚)Nr.   r/   Fr0   Tr1   r2   r)   )r3   r4   r5   zLocation list entry type z is not supported yetzUnknown DW_LLE code: )r   Úentry_end_offsetr™   r   r   r   r   r#   r   r%   r   r'   ÚNotImplementedErrorr   )r>   rš   rI   ÚoffÚlenÚtypes         r   Ú_translate_entry_v5z!LocationLists._translate_entry_v5ú   s2  € Ø× Ñ ˆØ×$Ñ$ sÑ*ˆØ×ÑˆØÐ(Ò(Ü# C¨¨e¯m©mÓ<Ð<ØÐ)Ò)Ü   c¨5×+=Ñ+=¸u×?OÑ?OÐQV×Q_ÑQ_ÐafÓgÐgØÐ*Ò*Ü   c¨5×+>Ñ+>À×@SÑ@SÐV[×VbÑVbÑ@bÐdi×drÑdrÐtxÓyÐyØÐ'Ò'Ü   c¨5×+>Ñ+>À×@QÑ@QÐSX×SaÑSaÐcgÓhÐhØÐ.Ò.Ü   c¨2¨r°5·>±>À4ÓHÐHØÐ[Ñ[õ &Ò\`Ð&bÓcÐcä™UÁÐ$GÓHÐHr   c                 ó’  — | j                   }|j                  |j                  «       d «      }g }|�–|j                  «       |k  rnt        | j                  j
                  |«      }|j                  t        |j                  |j                  |j                  «      «       |j                  «       |k  rŒn|j                  «       |k(  sJ ‚|S r   )rY   rv   rf   r   rA   ÚDwarf_locview_pairr�   r   r   ÚbeginÚend)r>   rz   rY   r~   ÚpairsÚpairs         r   ru   z"LocationLists._parse_locview_pairs  sŸ   € Ø—‘ˆØ—l‘l 6§;¡;£=°$Ó7ˆØˆØÐ"Ø—+‘+“- +Ò-Ü# D§L¡L×$CÑ$CÀVÓL�Ø—‘Ô-¨d×.?Ñ.?ÀÇÁÈTÏXÉXÓVÔWð —+‘+“- +Ó-ð —;‘;“= KÒ/Ð0Ð/Øˆr   )r9   Nr   )rQ   rR   rS   rT   rB   rG   rN   rP   ra   r`   r¡   ru   rU   r   r   r;   r;   A   s7   „ ñó"BóBò\2ò|\òó@
OòIó,	r   r;   c                   ó^   — e Zd ZdZd„ Zed„ «       Zd	d„Zed„ «       Zed„ «       Z	ed„ «       Z
y)
rk   a   A parser for location information in DIEs.
        Handles both location information contained within the attribute
        itself (represented as a LocationExpr object) and references to
        location lists in the .debug_loc section (represented as a
        list).
    c                 ó   — || _         y r   )Úlocation_lists)r>   rª   s     r   rB   zLocationParser.__init__"  s
   € Ø,ˆÕr   c                 óŒ   — t         j                  | «      xr. t         j                  | |«      xs t         j                  | |«      S )zB Checks if a DIE attribute contains location information.
        )rk   Ú_attribute_is_loclistptr_classÚ_attribute_has_loc_exprrl   ©r€   Údwarf_versions     r   ro   z%LocationParser.attribute_has_location%  sD   € ô ×=Ñ=¸dÓCò NÜ×7Ñ7¸¸mÓLò MÜ×7Ñ7¸¸mÓLð	Or   Nc                 óü   — | j                  ||«      r`| j                  ||«      rt        |j                  «      S | j	                  ||«      r&| j
                  j                  |j                  |«      S yt        d«      ‚)zY Parses a DIE attribute and returns either a LocationExpr or
            a list.
        z,Attribute does not have location informationN)ro   r­   r
   rm   rl   rª   rG   Ú
ValueError)r>   r€   r¯   rI   s       r   Úparse_from_attributez#LocationParser.parse_from_attribute-  sy   € ð ×&Ñ& t¨]Ô;Ø×+Ñ+¨D°-Ô@Ü# D§J¡JÓ/Ð/Ø×-Ñ-¨d°MÔBØ×*Ñ*×FÑFØ—J‘J ó%ð %ð Cô ÐKÓLÐLr   c                 óŒ   — |dk  xr- | j                   j                  d«      xr | j                  dk(   xs | j                   dk(  S )Nr9   ÚDW_FORM_blockÚDW_AT_const_valueÚDW_FORM_exprloc)ÚformÚ
startswithÚnamer®   s     r   r­   z&LocationParser._attribute_has_loc_expr@  sL   € à Ñ"ò 1 t§y¡y×';Ñ';¸OÓ'Lò 1Ø—	‘	Ð0Ñ0Ð0ò+à�I‰IÐ*Ñ*ð	,r   c                 óp   — |dk  xr  | j                   dv xr | j                  dk(   xs | j                   dv S )Nr9   )ÚDW_FORM_data1ÚDW_FORM_data2ÚDW_FORM_data4ÚDW_FORM_data8rµ   )ÚDW_FORM_sec_offsetÚDW_FORM_loclistx)r·   r¹   r®   s     r   rl   z&LocationParser._attribute_has_loc_listF  sL   € à Ñ"ò 6Ø—‘ÐbÐbò6à—Y‘YÐ"5Ñ5Ð5òHð —	‘	ÐGÐGð	Ir   c                 ó   — | j                   dv S )N)rd   ÚDW_AT_string_lengthrµ   ÚDW_AT_return_addrÚDW_AT_data_member_locationÚDW_AT_frame_baseÚDW_AT_segmentÚDW_AT_static_linkÚDW_AT_use_locationÚDW_AT_vtable_elem_locationÚDW_AT_call_valueÚDW_AT_GNU_call_site_valueÚDW_AT_GNU_call_site_targetÚDW_AT_GNU_call_site_data_value)r¹   )r€   s    r   r¬   z-LocationParser._attribute_is_loclistptr_classM  s   € à—	‘	ð 	Að 	Að 		Br   r   )rQ   rR   rS   rT   rB   Ústaticmethodro   r²   r­   rl   r¬   rU   r   r   rk   rk     sh   „ ñò-ð ñOó ðOóMð& ñ,ó ð,ð
 ñIó ðIð ñ
Bó ñ
Br   rk   )r^   Úcollectionsr   Úcommon.exceptionsr   Úcommon.utilsr   Ú
dwarf_utilr	   r
   r   r   r   r   r˜   Úobjectr7   r;   rk   rU   r   r   ú<module>rÔ      s¯   ðó 
Ý "Ý *Ý 'Ý ,á˜.¨*Ó5€Ù˜?Ð,tÓu€ÙÐ0Ð2ZÓ[Ð ÙÐ0Ð2JÓKÐ òrñ  iñ  Lñ  Zñ  MÙtñ  Bñ  Ø7ñ	€ôL˜ô Lô:X�Fô Xôt=B�Võ =Br   