
    d:/                     x    d dl Z d dlZd dlmZ ddlmZmZ ddl  edd      Z G d	 d
e	      Z
 G d de	      Zy)    N)
namedtuple   )struct_parsedwarf_assert   )*LineProgramEntryzcommand is_extended args statec                       e Zd ZdZd Zd Zy)	LineStatez Represents a line program state (or a "row" in the matrix
        describing debug location information for addresses).
        The instance variables of this class are the "state machine registers"
        described in section 6.2.2 of DWARFv3
    c                     d| _         d| _        d| _        d| _        d| _        || _        d| _        d| _        d| _        d| _	        d| _
        d| _        y )Nr   r   F)addressfilelinecolumnop_indexis_stmtbasic_blockend_sequenceprologue_endepilogue_beginisadiscriminator)selfdefault_is_stmts     </usr/lib/python3/dist-packages/elftools/dwarf/lineprogram.py__init__zLineState.__init__1   s[    		& !!#    c           
          dt        |       z  g}|j                  d| j                  z         dD ]#  }|j                  d|dt        | |             % dj	                  |      dz   S )Nz<LineState %x:z  address = 0x%x)
r   r   r   r   r   r   r   r   r   r   z  z = 
z>
)idappendr   getattrjoin)r   aattrs      r   __repr__zLineState.__repr__?   sk    4()	#dll23& 	@D HHD'$*=>?	@ yy|e##r   N)__name__
__module____qualname____doc__r   r&    r   r   r   r   +   s    
$r   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)LineProgramz Builds a "line table", which is essentially the matrix described
        in section 6.2 of DWARFv3. It's a list of LineState objects,
        sorted by increasing address, so it can be used to obtain the
        state information for each address.
    c                 X    || _         || _        || _        || _        || _        d| _        y)a  
            header:
                The header of this line program. Note: LineProgram may modify
                its header by appending file entries if DW_LNE_define_file
                instructions are encountered.

            stream:
                The stream this program can be read from.

            structs:
                A DWARFStructs instance suitable for this line program

            program_{start|end}_offset:
                Offset in the debug_line section stream where this program
                starts (the actual program, after the header), and where it
                ends.
                The actual range includes start but not end: [start, end - 1]
        N)streamheaderstructsprogram_start_offsetprogram_end_offset_decoded_entries)r   r0   r/   r1   r2   r3   s         r   r   zLineProgram.__init__O   s1    ( $8!"4 $r   c                 \    | j                   | j                         | _         | j                   S )a   Get the decoded entries for this line program. Return a list of
            LineProgramEntry objects.
            Note that this contains more information than absolutely required
            for the line table. The line table can be easily extracted from
            the list of entries by looking only at entries with non-None
            state. The extra information is mainly for the purposes of display
            with readelf and debugging.
        )r4   _decode_line_program)r   s    r   get_entrieszLineProgram.get_entriesj   s-       ($($=$=$?D!$$$r   c                      | j                   |   S )z6 Implement dict-like access to header entries
        )r0   )r   names     r   __getitem__zLineProgram.__getitem__y   s     {{4  r   c                    g t        | j                  d         dfd	}dfd	}| j                  }|| j                  k  r|t	        | j
                  j                  d      | j                  |      }|| j                  d   k\  r| d   }|| d   z
  }|| d   z  }| d	   j                  |z   |z  z  }xj                  |z  c_	        j                  |z   |z  _        | d
   || d   z  z   }	xj                  |	z  c_
         |||	|j                  g       n{|dk(  rt	        | j
                  j                  d      | j                        }
t	        | j
                  j                  d      | j                        }|t        k(  r3d_        d_         ||g d       t        | j                  d         n|t        k(  rDt	        | j
                  j!                  d      | j                        }|_	         |||gd       n|t"        k(  rLt	        | j
                  j$                  | j                        }| d   j'                  |        |||gd       n9|t(        k(  r8t	        | j
                  j                  d      | j                        }|_        n| j                  j-                  |
dz
  t.        j0                         n|t2        k(  r ||g        n|t4        k(  rbt	        | j
                  j                  d      | j                        }|| j                  d	   z  }xj                  |z  c_	         |||g       nJ|t6        k(  rFt	        | j
                  j9                  d      | j                        }xj                  |z  c_
        n|t:        k(  rBt	        | j
                  j                  d      | j                        }|_         |||g       n|t>        k(  rBt	        | j
                  j                  d      | j                        }|_          |||g       ne|tB        k(  rj                   _         ||g        n?|tD        k(  rd_#         ||g        n$|tH        k(  r6d| d   z
  }|| d   z  | d	   z  }xj                  |z  c_	         |||g       n|tJ        k(  rOt	        | j
                  jM                  d      | j                        }xj                  |z  c_	         |||g       n|tN        k(  rd_(         ||g        ns|tR        k(  rd_*         ||g        nY|tV        k(  rAt	        | j
                  j                  d      | j                        }|_,         |||g       nt[        dd|       | j                  j]                         }|| j                  k  r|S )Nr   Fc           
          j                  t        | ||t        j                                     d_        d_        d_        d_        y )Nr   F)r!   r	   copyr   r   r   r   )cmdargsis_extendedentriesstates      r   add_entry_new_statez=LineProgram._decode_line_program.<locals>.add_entry_new_state   sK     NN+[$		%(8: ;"#E %E!&E#(E r   c                 @    j                  t        | ||d              y )N)r!   r	   )r>   r?   r@   rA   s      r   add_entry_old_statez=LineProgram._decode_line_program.<locals>.add_entry_old_state   s    NN+CdDIJr    opcode_base"maximum_operations_per_instruction
line_rangeminimum_instruction_length	line_baser   T)r@   
file_entryr      z&Invalid standard line program opcode: )F)/r   r0   r2   r3   r   r1   Dwarf_uint8r/   r   r   r   Dwarf_uleb128DW_LNE_end_sequencer   r   DW_LNE_set_addressDwarf_target_addrDW_LNE_define_fileDwarf_lineprog_file_entryr!   DW_LNE_set_discriminatorr   seekosSEEK_CURDW_LNS_copyDW_LNS_advance_pcDW_LNS_advance_lineDwarf_sleb128DW_LNS_set_filer   DW_LNS_set_columnr   DW_LNS_negate_stmtDW_LNS_set_basic_blockr   DW_LNS_const_add_pcDW_LNS_fixed_advance_pcDwarf_uint16DW_LNS_set_prologue_endr   DW_LNS_set_epilogue_beginr   DW_LNS_set_isar   r   tell)r   rC   rE   offsetopcoderH   adjusted_opcodeoperation_advanceaddress_addendline_addendinst_len	ex_opcodeoperandrA   rB   s                @@r   r6   z LineProgram._decode_line_program~   s>   $++&789	)	K **t...!((,F ]3359:^5_2"(4+>">$3tL7I$I!56..+<<<=>  /"'..3D"DHj!j";/?T,EW3WX

k)
#[.%..IK1 ((B(B2(F(,5()A)A")E)-6	  33)-E&$%EM'	24H%dkk2C&DEE"44*4<<+I+I"+M+/;;8G$+EM'	G9$O"44*>>MG&--g6'	G9$O"::*4<<+E+Eb+I+/;;8G*1E' KK$$X\2;;? [('300*4<<+E+Eb+I+/;;8G  $++.J"KK #MM^3M'0@A22*4<<+E+Eb+I+/;;8GJJ')J.*4<<+E+Eb+I+/;;8G!(EJ'	:00*4<<+E+Eb+I+/;;8G#*EL'	:11(-$5EM'355(,E%'322&)D,?&?O'6$|:L'L&*+G&H'INMM^3M'0@A66*4<<+D+DR+H+/;;8GMMW,M'	:66)-E&'388+/E('3~-*4<<+E+Eb+I+/;;8G 'EI'	: )! "[[%%'Fi t...j r   N)r'   r(   r)   r*   r   r7   r:   r6   r+   r   r   r-   r-   I   s    
%6%!
Hr   r-   )rW   r=   collectionsr   common.utilsr   r   	constantsr	   objectr   r-   r+   r   r   <module>ru      sC    
  " 5 2 8: $ $<}& }r   