Current File : //usr/share/gdb/python/gdb/command/explore.pyo
�
�� Rc@sXdZddlZddlZejddkr:eZndefd��YZdefd��YZd	efd
��YZ	defd��YZ
d
efd��YZdefd��YZdefd��YZ
defd��YZdejfd��YZdejfd��YZdejfd��YZej�e�e�e�dS(sEImplementation of the GDB 'explore' command using the GDB Python API.i����NiitExplorercBs�eZdZiZejejejejej	ej
fZed��Z
ed��Zed��Zed��Zed��Zed��Zed��Zed��Zed	��ZRS(
s-Internal class which invokes other explorers.c	Cs�t|�}t}|ddkr9||ddkr9n�d}x�||kr�||}|dks�d|kr||dks�d|kr�|d	ks�d
|kr�|dkr�nt}P|d7}qBW|r�d|dS|SdS(Nit(it)t_tatztAtZt0t9(tlentFalsetTrue(texprtlengthtguardtitc((s,/usr/share/gdb/python/gdb/command/explore.pyt
guard_expr)s $
$0cCs]|jj}|tjkrGtj|}x.|j|||�rCq+Wndt|j�GHdS(s�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.
        s*Explorer for type '%s' not yet available.
N(ttypetcodeRttype_code_to_explorer_maptexplore_exprtstr(R
tvaluetis_childt	type_codetexplorer_class((s,/usr/share/gdb/python/gdb/command/explore.pyRAs
cCsW|j}|tjkrDtj|}x+|j|||�r@q(Wndt|�GHdS(s�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.
        s*Explorer for type '%s' not yet available.
N(RRRtexplore_typeR(tnametdatatypeRRR((s,/usr/share/gdb/python/gdb/command/explore.pyR[s	
cCs�ittj6ttj6ttj6ttj6ttj6ttj6ttj	6ttj
6ttj6t
tj6ttj6ttj6t_dS(s�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(tScalarExplorertgdbtTYPE_CODE_CHARt
TYPE_CODE_INTtTYPE_CODE_BOOLt
TYPE_CODE_FLTtTYPE_CODE_VOIDtTYPE_CODE_ENUMtCompoundExplorertTYPE_CODE_STRUCTtTYPE_CODE_UNIONtPointerExplorert
TYPE_CODE_PTRtReferenceExplorert
TYPE_CODE_REFtTypedefExplorertTYPE_CODE_TYPEDEFt
ArrayExplorertTYPE_CODE_ARRAYRR(((s,/usr/share/gdb/python/gdb/command/explore.pytinit_envus










cCs|jtjkS(s�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.
        (RRt_SCALAR_TYPE_LIST(R((s,/usr/share/gdb/python/gdb/command/explore.pytis_scalar_type�scCs	dGHdS(s�A utility function which prints that the current exploration session
        is returning to the parent value. Useful when exploring values.
        s
Returning to parent value...
N((((s,/usr/share/gdb/python/gdb/command/explore.pytreturn_to_parent_value�scCstd�dS(s�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.
        s(
Press enter to return to parent value: N(t	raw_input(((s,/usr/share/gdb/python/gdb/command/explore.pytreturn_to_parent_value_prompt�scCs	dGHdS(s�A utility function which prints that the current exploration session
        is returning to the enclosing type.  Useful when exploring types.
        s 
Returning to enclosing type...
N((((s,/usr/share/gdb/python/gdb/command/explore.pytreturn_to_enclosing_type�scCstd�dS(s�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.
        s*
Press enter to return to enclosing type: N(R6(((s,/usr/share/gdb/python/gdb/command/explore.pytreturn_to_enclosing_type_prompt�s(t__name__t
__module__t__doc__RR R!R"R#R$R%R&R3tstaticmethodRRRR2R4R5R7R8R9(((s,/usr/share/gdb/python/gdb/command/explore.pyRs"RcBs,eZdZed��Zed��ZRS(s-Internal class used to explore scalar values.cCsHd||jfGHd|t|�fGH|rDtj�tj�ntS(s�Function to explore scalar values.
        See Explorer.explore_expr and Explorer.is_scalar_type for more
        information.
        s$'%s' is a scalar value of type '%s'.s%s = %s(RRRR7R5R(R
RR((s,/usr/share/gdb/python/gdb/command/explore.pyR�s

cCs�|jtjkr<|r0d|t|�fGHqcd|GHn'|rZd|t|�fGHn	d|GH|r�tj�tj�ntS(s�Function to explore scalar types.
        See Explorer.explore_type and Explorer.is_scalar_type for more
        information.
        s!%s is of an enumerated type '%s'.s'%s' is an enumerated type.s%s is of a scalar type '%s'.s'%s' is a scalar type.(RR R&RRR9R8R(RRR((s,/usr/share/gdb/python/gdb/command/explore.pyR�s	

(R:R;R<R=RR(((s,/usr/share/gdb/python/gdb/command/explore.pyR�sR*cBs,eZdZed��Zed��ZRS(s.Internal class used to explore pointer values.cCs�d|t|jj��fGHtd�}|dkr�d}y|j�}t|�Wn1tjk
r�d|GH|r�tj	�nt
SXtjdtj|�||�t
Std�}|dkrsx�t
rnd}yttd|��}Wntk
rPnXd	tj|�|f}||}yt|�Wn tjk
rWd
|GHq�nXtj||t
�q�Wt
S|r�tj�nt
S(sdFunction to explore pointer values.
        See Explorer.explore_expr for more information.
        s)'%s' is a pointer to a value of type '%s's<Continue exploring it as a pointer to a single value [y/n]: tys6'%s' a pointer pointing to an invalid memory location.s*%ss6Continue exploring it as a pointer to an array [y/n]: is<Enter the index of the element you want to explore in '%s': s%s[%d]sCannot read value at index %d.N(RRttargetR6tNonetdereferenceR tMemoryErrorRR7RRRRtintt
ValueErrorR5(R
RRtoptiontderef_valuetindextelement_exprtelement((s,/usr/share/gdb/python/gdb/command/explore.pyR�sL

		

	
cCs<|j�}d|t|�fGHtjd|||�tS(scFunction to explore pointer types.
        See Explorer.explore_type for more information.
        s)
%s is a pointer to a value of type '%s'.sthe pointee type of %s(R?RRRR(RRRttarget_type((s,/usr/share/gdb/python/gdb/command/explore.pyRs
(R:R;R<R=RR(((s,/usr/share/gdb/python/gdb/command/explore.pyR*�s0R,cBs,eZdZed��Zed��ZRS(s@Internal class used to explore reference (TYPE_CODE_REF) values.cCs#|j�}tj|||�tS(sbFunction to explore array values.
        See Explorer.explore_expr for more information.
        (treferenced_valueRRR(R
RRRK((s,/usr/share/gdb/python/gdb/command/explore.pyR/scCs#|j�}tj|||�tS(scFunction to explore pointer types.
        See Explorer.explore_type for more information.
        (R?RRR(RRRRJ((s,/usr/share/gdb/python/gdb/command/explore.pyR8s(R:R;R<R=RR(((s,/usr/share/gdb/python/gdb/command/explore.pyR,,s	R0cBs,eZdZed��Zed��ZRS(s&Internal class used to explore arrays.cCs�|jj�}d|t|�fGHd}yttd|��}Wn%tk
rk|rgtj�ntSXd}y||}t|�Wn(t
jk
r�d|GHtd�tSXtj
dtj|�|f|t�tS(sbFunction to explore array values.
        See Explorer.explore_expr for more information.
        s'%s' is an array of '%s'.is<Enter the index of the element you want to explore in '%s': sCannot read value at index %d.sPress enter to continue... s%s[%d]N(RR?RRCR6RDRR5RR@R RBRRR(R
RRRJRGRI((s,/usr/share/gdb/python/gdb/command/explore.pyREs*	


	

cCs<|j�}d|t|�fGHtjd|||�tS(saFunction to explore array types.
        See Explorer.explore_type for more information.
        s%s is an array of '%s'.sthe array element of %s(R?RRRR(RRRRJ((s,/usr/share/gdb/python/gdb/command/explore.pyRbs
(R:R;R<R=RR(((s,/usr/share/gdb/python/gdb/command/explore.pyR0BsR'cBsJeZdZed��Zed��Zed��Zed��ZRS(s:Internal class used to explore struct, classes and unions.cCsod}x7|D]/}|t|d�kr
t|d�}q
q
Wx(|D] }d||d|dfGHqGWdS(sKInternal function which prints the fields of a struct/class/union.
        is
  %*s = %siN(R
(t
print_listtmax_field_name_lengthtpair((s,/usr/share/gdb/python/gdb/command/explore.pyt
_print_fieldsrs

cCs1d}x$|D]}|js
|d}q
q
W|S(Nii(t
artificial(tfieldstreal_field_counttfield((s,/usr/share/gdb/python/gdb/command/explore.pyt_get_real_field_count~s

	cCsz|j}|j}|j�}|tjkr6d}nd}tj|�dkr�d||t|j�fGH|rtj	�nt
Sd||t|j�fGHt
}i}d}	g}
x=|D]5}|jr�q�ntj|�d|j
}|jr
|j|j�}
n
||j
}
d}|tjkrNd|	t|j�f}t}nntj|j�r�d	t|
�t|j�f}n:|jr�d
}nd}d|	|t|j�f}t}||
f|t|	�<|	d
}	|
j|j
|f�q�Wtj|
�dGH|rctd�}||krMtj||d||d
t�tS|rvtj�qvn|rvtj	�nt
S(svFunction to explore structs/classes and union values.
        See Explorer.explore_expr for more information.
        sstruct/classtunionis6The value of '%s' is a %s of type '%s' with no fields.sBThe value of '%s' is a %s of type '%s' with the following fields:
t.ts-<Enter %d to explore this field of type '%s'>s%s .. (Value of type '%s')s
base classRSs*<Enter %d to explore this %s of type '%s'>is"Enter the field number of choice: (RRRQR R(R'RTRRR7RRPRRt
is_base_classtcastR)RR4tappendROR6RR5(R
RRRRRQt	type_descthas_explorable_fieldstchoice_to_compound_field_maptcurrent_choiceRLRStfield_full_nametfield_valuet
literal_valuet
field_desctchoice((s,/usr/share/gdb/python/gdb/command/explore.pyR�sr			

		
			


cCs>|j}d}|tjkr'd}nd}|j�}tj|�dkr�|ryd||t|�fGHtj�nd||fGHt	S|r�d||t|�fGHnd||fGHt	}d}i}g}	x�|D]�}
|
j
r�q�n|
jrd	}nd
}d||t|
j�f}|	j
|
j|f�|
j|
j|f|t|�<|d}q�Wtj|	�dGHt|�dkr'td
�}
|
|kr|r�d||
d||
d|f}n#d||
d||
d|f}tj|||
dt�tS|r:tj�q:n|r:tj�nt	S(srFunction to explore struct/class and union types.
        See Explorer.explore_type for more information.
        RWsstruct/classRUis'%s is a %s of type '%s' with no fields.s'%s' is a %s with no fields.s3%s is a %s of type '%s' with the following fields:
s('%s' is a %s with the following fields:
s
base classRSs*<Enter %d to explore this %s of type '%s'>is"Enter the field number of choice: s
%s '%s' of %sis%s '%s' of '%s'(RR R(RQR'RTRRR9RRPRXRRZRROR
R6RRR8(RRRRR[RQR\R^R]RLRSRbtrhsRctnew_name((s,/usr/share/gdb/python/gdb/command/explore.pyR�sn		

			


	
(R:R;R<R=RORTRR(((s,/usr/share/gdb/python/gdb/command/explore.pyR'os
	QR.cBs,eZdZed��Zed��ZRS(s>Internal class used to explore values whose type is a typedef.cCsP|jj�}d|t|j�t|�fGHtj||j|�|�tS(sdFunction to explore typedef values.
        See Explorer.explore_expr for more information.
        sAThe value of '%s' is of type '%s' which is a typedef of type '%s'(Rtstrip_typedefsRRRRYR(R
RRtactual_type((s,/usr/share/gdb/python/gdb/command/explore.pyR)s
cCsV|j�}|r*d|t|�fGHnd|t|�fGHtj|||�tS(scFunction to explore typedef types.
        See Explorer.explore_type for more information.
        s)The type of %s is a typedef of type '%s'.s(The type '%s' is a typedef of type '%s'.(RfRRRR(RRRRg((s,/usr/share/gdb/python/gdb/command/explore.pyR6s(R:R;R<R=RR(((s,/usr/share/gdb/python/gdb/command/explore.pyR.&s
tExploreUtilscBs;eZdZed��Zed��Zed��ZRS(sEInternal class which provides utilities for the main command classes.cCs1t|�dkr)tjd|��tStSdS(s�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.
        is!ERROR: '%s' requires an argument.N(R
R tGdbErrorRR(Rtarg_str((s,/usr/share/gdb/python/gdb/command/explore.pyt
check_argsJs
	
cCs\ytjd|�jj�SWn7tk
rWytj|�SWqXtk
rSdSXnXdS(s<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.
        s(%s *)0N(R tparse_and_evalRR?tRuntimeErrortlookup_typeR@(ttype_str((s,/usr/share/gdb/python/gdb/command/explore.pytget_type_from_str`s

cCs*ytj|�SWntk
r%dSXdS(sCA 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 RlRmR@(t	value_str((s,/usr/share/gdb/python/gdb/command/explore.pytget_value_from_strws
(R:R;R<R=RkRpRr(((s,/usr/share/gdb/python/gdb/command/explore.pyRhGstExploreCommandcBs eZdZd�Zd�ZRS(s,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.
    cCs,tt|�jdddtjdt�dS(NRtexploret
command_classtprefix(tsuperRst__init__R tCOMMAND_DATAR(tself((s,/usr/share/gdb/python/gdb/command/explore.pyRx�s	cCs�tjd|�tkrdStj|�}|dk	rNtj||t�dStj|�}|dk	r�tj||t�dSt	j
d|��dS(NRtsG'%s' neither evaluates to a value nor is a type in the current context.(RhRkRRrR@RRRpRR Ri(RzRjtfrom_ttyRR((s,/usr/share/gdb/python/gdb/command/explore.pytinvoke�s(R:R;R<RxR|(((s,/usr/share/gdb/python/gdb/command/explore.pyRs�s
	tExploreValueCommandcBs eZdZd�Zd�ZRS(sExplore 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.
    cCs&tt|�jdddtj�dS(NRs
explore valueRu(RwR}RxR Ry(Rz((s,/usr/share/gdb/python/gdb/command/explore.pyRx�scCsetjd|�tkrdStj|�}|dkrNtjd|��dStj||t�dS(Ns
explore values: '%s' does not evaluate to a value in the current context.(	RhRkRRrR@R RiRR(RzRjR{R((s,/usr/share/gdb/python/gdb/command/explore.pyR|�s
(R:R;R<RxR|(((s,/usr/share/gdb/python/gdb/command/explore.pyR}�s
	tExploreTypeCommandcBs eZdZd�Zd�ZRS(s:Explore a type or the type of an expression valid in the current
       context.

       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.
    cCs&tt|�jdddtj�dS(NRsexplore typeRu(RwR~RxR Ry(Rz((s,/usr/share/gdb/python/gdb/command/explore.pyRx�scCs�tjd|�tkrdStj|�}|dk	rNtj||t�dStj|�}|dk	r�d|t|j	�fGHtjt|j	�|j	t�dSt
jd|��dS(Nsexplore types'%s' is of type '%s'.s3'%s' is not a type or value in the current context.(RhRkRRpR@RRRrRRR Ri(RzRjR{RR((s,/usr/share/gdb/python/gdb/command/explore.pyR|�s	(R:R;R<RxR|(((s,/usr/share/gdb/python/gdb/command/explore.pyR~�s	(R<R tsystversion_infotinputR6tobjectRRR*R,R0R'R.RhtCommandRsR}R~R2(((s,/usr/share/gdb/python/gdb/command/explore.pyt<module>s&	�-B-�!B($