Current File : //proc/self/root/kunden/usr/share/gdb/python/gdb/command/__pycache__/explore.cpython-39.pyc
a

ɱZhh�@s�dZddlZGdd�de�ZGdd�de�ZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�Z	Gdd�de�Z
Gdd�dej�ZGdd�dej�Z
Gdd�dej�Ze��e�e
�e�dS)zEImplementation of the GDB 'explore' command using the GDB Python API.�Nc@s�eZdZdZiZejejejej	ej
ejfZe
dd��Ze
dd��Ze
dd��Ze
dd	��Ze
d
d��Ze
dd
��Ze
dd��Ze
dd��Ze
dd��ZdS)�Explorerz-Internal class which invokes other explorers.cCs�t|�}d}|ddkr*||ddkr*n^d}||kr�||}|dks~d|krV|dks~d	|krf|d
ks~d|krx|dkrxnd
}q�|d7}q.|r�d|dS|SdS)NFr�(��)�_�a�z�A�Z�0�9T)�len)�expr�lengthZguard�i�c�r�,/usr/share/gdb/python/gdb/command/explore.py�
guard_expr%s8�������
zExplorer.guard_exprcCsD|jj}|tjvr.tj|}|�|||�r@qntdt|j��dS)a�Main function to explore an expression value.

        Arguments:
            expr: The expression string that is being explored.
            value: The gdb.Value value of the expression.
            is_child: Boolean value to indicate if the expression is a child.
                      An expression is a child if it is derived from the main
                      expression entered by the user.  For example, if the user
                      entered an expression which evaluates to a struct, then
                      when exploring the fields of the struct, is_child is set
                      to True internally.

        Returns:
            No return value.
        �*Explorer for type '%s' not yet available.
N)�type�coder�type_code_to_explorer_map�explore_expr�print�str)r�value�is_child�	type_code�explorer_classrrrrAs

zExplorer.explore_exprcCs@|j}|tjvr,tj|}|�|||�r<qntdt|��dS)a�Main function to explore a data type.

        Arguments:
            name: The string representing the path to the data type being
                  explored.
            datatype: The gdb.Type value of the data type being explored.
            is_child: Boolean value to indicate if the name is a child.
                      A name is a child if it is derived from the main name
                      entered by the user.  For example, if the user entered
                      the name of struct type, then when exploring the fields
                      of the struct, is_child is set to True internally.

        Returns:
            No return value.
        rN)rrr�explore_typerr)�name�datatyperrrrrrr Zs

zExplorer.explore_typecCsXtjttjttjttjttjttjttjt	tj
t	tjttj
ttjttjttjti
t_dS)z�Initializes the Explorer environment.
        This function should be invoked before starting any exploration.  If
        invoked before an exploration, it need not be invoked for subsequent
        explorations.
        N)�gdb�TYPE_CODE_CHAR�ScalarExplorer�
TYPE_CODE_INT�TYPE_CODE_BOOL�
TYPE_CODE_FLT�TYPE_CODE_VOID�TYPE_CODE_ENUM�TYPE_CODE_STRUCT�CompoundExplorer�TYPE_CODE_UNIONZ
TYPE_CODE_PTR�PointerExplorerZ
TYPE_CODE_REF�ReferenceExplorerZTYPE_CODE_RVALUE_REFZTYPE_CODE_TYPEDEF�TypedefExplorerZTYPE_CODE_ARRAY�
ArrayExplorerrrrrrr�init_envss�zExplorer.init_envcCs|jtjvS)a�Checks whether a type is a scalar type.
        A type is a scalar type of its type is
            gdb.TYPE_CODE_CHAR or
            gdb.TYPE_CODE_INT or
            gdb.TYPE_CODE_BOOL or
            gdb.TYPE_CODE_FLT or
            gdb.TYPE_CODE_VOID or
            gdb.TYPE_CODE_ENUM.

        Arguments:
            type: The type to be checked.

        Returns:
            'True' if 'type' is a scalar type. 'False' otherwise.
        )rr�_SCALAR_TYPE_LIST)rrrr�is_scalar_type�szExplorer.is_scalar_typecCstd�dS)z�A utility function which prints that the current exploration session
        is returning to the parent value. Useful when exploring values.
        z
Returning to parent value...
N�rrrrr�return_to_parent_value�szExplorer.return_to_parent_valuecCstd�dS)z�A utility function which prompts the user to press the 'enter' key
        so that the exploration session can shift back to the parent value.
        Useful when exploring values.
        z(
Press enter to return to parent value: N��inputrrrr�return_to_parent_value_prompt�sz&Explorer.return_to_parent_value_promptcCstd�dS)z�A utility function which prints that the current exploration session
        is returning to the enclosing type.  Useful when exploring types.
        z 
Returning to enclosing type...
Nr5rrrr�return_to_enclosing_type�sz!Explorer.return_to_enclosing_typecCstd�dS)z�A utility function which prompts the user to press the 'enter' key
        so that the exploration session can shift back to the enclosing type.
        Useful when exploring types.
        z*
Press enter to return to enclosing type: Nr7rrrr�return_to_enclosing_type_prompt�sz(Explorer.return_to_enclosing_type_promptN)�__name__�
__module__�__qualname__�__doc__rr#r$r&r'r(r)r*r3�staticmethodrrr r2r4r6r9r:r;rrrrrs6�	







rc@s(eZdZdZedd��Zedd��ZdS)r%z-Internal class used to explore scalar values.cCs>td||jf�td|t|�f�|r:t��t��dS)z�Function to explore scalar values.
        See Explorer.explore_expr and Explorer.is_scalar_type for more
        information.
        z$'%s' is a scalar value of type '%s'.z%s = %sF)rrrrr9r6)rrrrrrr�szScalarExplorer.explore_exprcCsr|jtjkr4|r&td|t|�f�qZtd|�n&|rNtd|t|�f�ntd|�|rnt��t��dS)z�Function to explore scalar types.
        See Explorer.explore_type and Explorer.is_scalar_type for more
        information.
        z!%s is of an enumerated type '%s'.z'%s' is an enumerated type.z%s is of a scalar type '%s'.z'%s' is a scalar type.F)rr#r*rrrr;r:)r!r"rrrrr �szScalarExplorer.explore_typeN�r<r=r>r?r@rr rrrrr%�s

r%c@s(eZdZdZedd��Zedd��ZdS)r.z.Internal class used to explore pointer values.cCsFtd|t|j���f�td�}|dkr�d}z|��}t|�Wn.tjyptd|�|rjt�	�YdS0t�
dt�|�||�dStd�}|dk�r4d	}zttd
|��}Wnt
y�Y�q0Yn0dt�|�|f}||}zt|�Wn&tj�ytd|�Yq�Yn0t�
||d
�q�dS|�rBt��dS)zdFunction to explore pointer values.
        See Explorer.explore_expr for more information.
        z)'%s' is a pointer to a value of type '%s'z<Continue exploring it as a pointer to a single value [y/n]: �yNz6'%s' a pointer pointing to an invalid memory location.Fz*%sz6Continue exploring it as a pointer to an array [y/n]: r�<Enter the index of the element you want to explore in '%s': �%s[%d]�Cannot read value at index %d.T)rrr�targetr8Zdereferencer#�MemoryErrorrr9rr�int�
ValueErrorr6)rrr�optionZderef_value�indexZelement_expr�elementrrrr�sb�����
���
zPointerExplorer.explore_exprcCs2|��}td|t|�f�t�d|||�dS)�cFunction to explore pointer types.
        See Explorer.explore_type for more information.
        z)
%s is a pointer to a value of type '%s'.zthe pointee type of %sF�rFrrrr �r!r"r�target_typerrrr !szPointerExplorer.explore_typeNrArrrrr.�s

7r.c@s(eZdZdZedd��Zedd��ZdS)r/z@Internal class used to explore reference (TYPE_CODE_REF) values.cCs|��}t�|||�dS)�bFunction to explore array values.
        See Explorer.explore_expr for more information.
        F)�referenced_valuerr)rrrrRrrrr0szReferenceExplorer.explore_exprcCs|��}t�|||�dS)rMF)rFrr rOrrrr 9szReferenceExplorer.explore_typeNrArrrrr/-s

r/c@s(eZdZdZedd��Zedd��ZdS)r1z&Internal class used to explore arrays.cCs�|j��}td|t|�f�d}zttd|��}Wn tyV|rPt��YdS0d}z||}t|�Wn*t	j
y�td|�td�YdS0t�d	t�|�|f|d�dS)
rQz'%s' is an array of '%s'.rrCFNrEzPress enter to continue... TrD)
rrFrrrHr8rIrr6r#rGrr)rrrrPrKrLrrrrFs6
����zArrayExplorer.explore_exprcCs2|��}td|t|�f�t�d|||�dS)zaFunction to explore array types.
        See Explorer.explore_type for more information.
        z%s is an array of '%s'.zthe array element of %sFrNrOrrrr hszArrayExplorer.explore_typeNrArrrrr1Cs

!r1c@s@eZdZdZedd��Zedd��Zedd��Zedd	��Zd
S)r,z:Internal class used to explore struct, classes and unions.cCsRd}|D] }|t|d�krt|d�}q|D]}td||d|df�q.dS)zBInternal function which prints the fields of a struct/class/union.rz
  %*s = %srN)r
r)�
print_listZmax_field_name_lengthZpairrrr�
_print_fieldswszCompoundExplorer._print_fieldscCs d}|D]}|js|d}q|S)Nrr)�
artificial)�fieldsZreal_field_count�fieldrrr�_get_real_field_count�s

z&CompoundExplorer._get_real_field_countcCs�|j}|j}|��}|tjkr$d}nd}t�|�dkr^td||t|j�f�|rZt	�
�dStd||t|j�f�d}i}d}	g}
|D]�}|jr�q�t	�|�d|j
}|jr�|�|j�}
n
||j
}
d}|tjkr�d	|	t|j�f}d
}nPt	�|j��rdt|
�t|j�f}n*|j�r"d}nd
}d|	|t|j�f}d
}||
f|t|	�<|	d}	|
�|j
|f�q�t�|
�td�|�r�td�}||v�r�t	�||d||dd
�d
S|�r�t	��n|�r�t	�
�dS)zvFunction to explore structs/classes and union values.
        See Explorer.explore_expr for more information.
        �struct/class�unionrz6The value of '%s' is a %s of type '%s' with no fields.FzBThe value of '%s' is a %s of type '%s' with the following fields:
�.�z-<Enter %d to explore this field of type '%s'>Tz%s .. (Value of type '%s')�
base classrW�*<Enter %d to explore this %s of type '%s'>r�"Enter the field number of choice: )rrrVr#r+r,rXrrrr9rUrr!�
is_base_class�castr-r4�appendrTr8rr6)rrrr"rrV�	type_descZhas_explorable_fields�choice_to_compound_field_map�current_choicerSrWZfield_full_nameZfield_valueZ
literal_value�
field_desc�choicerrrr�s�
����

����



�
zCompoundExplorer.explore_exprcCs�|j}d}|tjkrd}nd}|��}t�|�dkrl|rXtd||t|�f�t�	�ntd||f�dS|r�td||t|�f�ntd	||f�d}i}g}|D]^}	|	j
r�q�|	jr�d
}
nd}
d||
t|	j�f}|�
|	j|f�|	j|	j|
f|t|�<|d
}q�t�|�td�t|�dk�r�td�}||v�r�|�r`d||d||d|f}
nd||d||d|f}
t�|
||d
d�dS|�r�t��n|�r�t�	�dS)zrFunction to explore struct/class and union types.
        See Explorer.explore_type for more information.
        r\rYrZrz'%s is a %s of type '%s' with no fields.z'%s' is a %s with no fields.Fz3%s is a %s of type '%s' with the following fields:
z('%s' is a %s with the following fields:
r]rWr^rr_z
%s '%s' of %s�z%s '%s' of '%s'T)rr#r+rVr,rXrrrr;rUr`rrbr!rTr
r8r r:)r!r"rrrcrVrerdrSrWrfZrhsrg�new_namerrrr �s�
��
����




�

��
zCompoundExplorer.explore_typeN)	r<r=r>r?r@rTrXrr rrrrr,ts



]r,c@s(eZdZdZedd��Zedd��ZdS)r0z>Internal class used to explore values whose type is a typedef.cCs>|j��}td|t|j�t|�f�t�||�|�|�dS)zdFunction to explore typedef values.
        See Explorer.explore_expr for more information.
        zAThe value of '%s' is of type '%s' which is a typedef of type '%s'F)r�strip_typedefsrrrrra)rrr�actual_typerrrrCs
��zTypedefExplorer.explore_exprcCsH|��}|r"td|t|�f�ntd|t|�f�t�|||�dS)zcFunction to explore typedef types.
        See Explorer.explore_type for more information.
        z)The type of %s is a typedef of type '%s'.z(The type '%s' is a typedef of type '%s'.F)rjrrrr )r!r"rrkrrrr Rs�zTypedefExplorer.explore_typeNrArrrrr0@s

r0c@s4eZdZdZedd��Zedd��Zedd��ZdS)	�ExploreUtilszEInternal class which provides utilities for the main command classes.cCs&t|�dkrt�d|��dSdSdS)a�Utility to check if adequate number of arguments are passed to an
        explore command.

        Arguments:
            name: The name of the explore command.
            arg_str: The argument string passed to the explore command.

        Returns:
            True if adequate arguments are passed, false otherwise.

        Raises:
            gdb.GdbError if adequate arguments are not passed.
        rz!ERROR: '%s' requires an argument.FTN)r
r#�GdbError)r!�arg_strrrr�
check_argsfszExploreUtils.check_argscCsVzt�d|�j��WStyPzt�|�WYStyJYYdS0Yn0dS)a<A utility function to deduce the gdb.Type value from a string
        representing the type.

        Arguments:
            type_str: The type string from which the gdb.Type value should be
                      deduced.

        Returns:
            The deduced gdb.Type value if possible, None otherwise.
        z(%s *)0N)r#�parse_and_evalrrF�RuntimeErrorZlookup_type)Ztype_strrrr�get_type_from_str{szExploreUtils.get_type_from_strcCs&zt�|�WSty YdS0dS)aCA utility function to deduce the gdb.Value value from a string
        representing the value.

        Arguments:
            value_str: The value string from which the gdb.Value value should
                       be deduced.

        Returns:
            The deduced gdb.Value value if possible, None otherwise.
        N)r#rprq)Z	value_strrrr�get_value_from_str�szExploreUtils.get_value_from_strN)r<r=r>r?r@rorrrsrrrrrlcs

rlcs(eZdZdZ�fdd�Zdd�Z�ZS)�ExploreCommanda	Explore a value or a type valid in the current context.

    Usage: explore ARG

    - ARG is either a valid expression or a type name.
    - At any stage of exploration, hit the return key (instead of a
    choice, if any) to return to the enclosing type or value.cstt|�jdtjdd�dS)N�exploreT)r!�
command_class�prefix)�superrt�__init__r#�COMMAND_DATA��self��	__class__rrry�s
�zExploreCommand.__init__cCsnt�d|�durdSt�|�}|dur8t�||d�dSt�|�}|dur\t�||d�dSt�d|��dS)NruFzG'%s' neither evaluates to a value nor is a type in the current context.)	rlrorsrrrrr r#rm)r|rn�from_ttyrr"rrr�invoke�s

��zExploreCommand.invoke�r<r=r>r?ryr��
__classcell__rrr}rrt�srtcs(eZdZdZ�fdd�Zdd�Z�ZS)�ExploreValueCommandz�Explore value of an expression valid in the current context.

    Usage: explore value ARG

    - ARG is a valid expression.
    - At any stage of exploration, hit the return key (instead of a
    choice, if any) to return to the enclosing value.cstt|�jdtjd�dS)N�
explore value�r!rv)rxr�ryr#rzr{r}rrry�s
�zExploreValueCommand.__init__cCsJt�d|�durdSt�|�}|dur8t�d|��dSt�||d�dS)Nr�Fz: '%s' does not evaluate to a value in the current context.)rlrorsr#rmrr)r|rnrrrrrr��s
��zExploreValueCommand.invoker�rrr}rr��sr�cs(eZdZdZ�fdd�Zdd�Z�ZS)�ExploreTypeCommandz�Explore a type or the type of an expression.

    Usage: explore type ARG

    - ARG is a valid expression or a type name.
    - At any stage of exploration, hit the return key (instead of a
    choice, if any) to return to the enclosing type.cstt|�jdtjd�dS)N�explore typer�)rxr�ryr#rzr{r}rrry�s
�zExploreTypeCommand.__init__cCs�t�d|�durdSt�|�}|dur8t�||d�dSt�|�}|durztd|t|j�f�t�t|j�|jd�dSt	�
d|��dS)Nr�Fz'%s' is of type '%s'.z3'%s' is not a type or value in the current context.)rlrorrrr rsrrrr#rm)r|rnrr"rrrrr��s

�zExploreTypeCommand.invoker�rrr}rr��sr�)r?r#�objectrr%r.r/r1r,r0rlZCommandrtr�r�r2rrrr�<module>s$'*G1M#A'"