ó ›à Rc@sXdZddlZddlZejddkr:eZndefd„ƒYZdefd„ƒYZd efd „ƒYZ d efd „ƒYZ d efd„ƒYZ defd„ƒ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 fZ e 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¯|d kr¯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 6t tj 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 SXtj dtj |ƒ||ƒ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(RRttargetR6tNonet dereferenceR t MemoryErrorRR7R RRR tintt ValueErrorR5(R RRtoptiont deref_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 (RRRt target_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 j k 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?RRCR6RDRR5R R@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} | j rÒ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-s%s .. (Value of type '%s')s base classRSs*is"Enter the field number of choice: (RRRQR R(R'RTRRR7R RPRRt is_base_classtcastR)R R4tappendROR6RR5(R RRRRRQt type_descthas_explorable_fieldstchoice_to_compound_field_maptcurrent_choiceRLRStfield_full_namet field_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| j rd } 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*is"Enter the field number of choice: s %s '%s' of %sis%s '%s' of '%s'(RR R(RQR'RTRRR9R RPRXRRZRROR 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 RRt actual_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 tGdbErrorR R (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 RuntimeErrort lookup_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.( RhRkR RrR@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.( RhRkR RrR@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 j d|ƒ‚dS(Ns explore types'%s' is of type '%s'.s3'%s' is not a type or value in the current context.( RhRkR RpR@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.pyts&   £-B-·!B($