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

ɱZh18�@s�dZddlZddlZddlZddlZGdd�de�ZGdd�de�Zddd	�ZGd
d�de�Z	Gdd
�d
ej
�ZGdd�de�ZGdd�dej
�Z
Gdd�dej
�ZGdd�dej
�ZGdd�dej
�Zdd�Ze	d�Zede�dd�ZdS)z+Utilities for working with pretty-printers.�Nc@s"eZdZdZddd�Zdd�ZdS)�
PrettyPrinteraA basic pretty-printer.

    Attributes:
        name: A unique string among all printers for the context in which
            it is defined (objfile, progspace, or global(gdb)), and should
            meaningfully describe what can be pretty-printed.
            E.g., "StringPiece" or "protobufs".
        subprinters: An iterable object with each element having a `name'
            attribute, and, potentially, "enabled" attribute.
            Or this is None if there are no subprinters.
        enabled: A boolean indicating if the printer is enabled.

    Subprinters are for situations where "one" pretty-printer is actually a
    collection of several printers.  E.g., The libstdc++ pretty-printer has
    a pretty-printer for each of several different types, based on regexps.
    NcCs||_||_d|_dS�NT)�name�subprinters�enabled)�selfrr�r�%/usr/share/gdb/python/gdb/printing.py�__init__/szPrettyPrinter.__init__cCstd��dS)NzPrettyPrinter __call__)�NotImplementedError)r�valrrr	�__call__4szPrettyPrinter.__call__)N)�__name__�
__module__�__qualname__�__doc__r
r
rrrr	rs
rc@seZdZdZdd�ZdS)�SubPrettyPrinterz�Baseclass for sub-pretty-printers.

    Sub-pretty-printers needn't use this, but it formalizes what's needed.

    Attributes:
        name: The name of the subprinter.
        enabled: A boolean indicating if the subprinter is enabled.
    cCs||_d|_dSr)rr�rrrrr	r
CszSubPrettyPrinter.__init__N)rrrrr
rrrr	r9s	rFcCsNt|d�st|d�std��t|d�r8t|d�s8td��t|d�sJtd��t|d�r\|j}n|j}|dusr|tur�t�d	�r�t�d
|�t}nt�d	�r�t�d||jf�t|d��r<t|jt	�s�td��|j�
d
�dkr�td��d}|jD]J}t|d��r2|j|jk�r2|�r$|j|=�q<nt
d|j��|d}q�|j�d|�dS)a�Register pretty-printer PRINTER with OBJ.

    The printer is added to the front of the search list, thus one can override
    an existing printer if one needs to.  Use a different name when overriding
    an existing printer, otherwise an exception will be raised; multiple
    printers with the same name are disallowed.

    Arguments:
        obj: Either an objfile, progspace, or None (in which case the printer
            is registered globally).
        printer: Either a function of one argument (old way) or any object
            which has attributes: name, enabled, __call__.
        replace: If True replace any existing copy of the printer.
            Otherwise if the printer already exists raise an exception.

    Returns:
        Nothing.

    Raises:
        TypeError: A problem with the type of the printer.
        ValueError: The printer's name contains a semicolon ";".
        RuntimeError: A printer with the same name is already registered.

    If the caller wants the printer to be listable and disableable, it must
    follow the PrettyPrinter API.  This applies to the old way (functions) too.
    If printer is an object, __call__ is a method of two arguments:
    self, and the value to be pretty-printed.  See PrettyPrinter.
    rrzprinter missing attribute: namerz"printer missing attribute: enabledr
z#printer missing attribute: __call__N�verbosez)Registering global %s pretty-printer ...
z)Registering %s pretty-printer for %s ...
zprinter name is not a string�;rzsemicolon ';' in printer namez%pretty-printer already registered: %s�)�hasattr�	TypeErrorrr�gdbZ	parameter�write�filename�
isinstance�str�find�
ValueErrorZpretty_printers�RuntimeError�insert)�obj�printer�replacer�i�prrr	�register_pretty_printerHsB"



�
�
r'cs@eZdZdZGdd�de�Z�fdd�Zdd�Zdd	�Z�Z	S)
�RegexpCollectionPrettyPrinterayClass for implementing a collection of regular-expression based pretty-printers.

    Intended usage:

    pretty_printer = RegexpCollectionPrettyPrinter("my_library")
    pretty_printer.add_printer("myclass1", "^myclass1$", MyClass1Printer)
    ...
    pretty_printer.add_printer("myclassN", "^myclassN$", MyClassNPrinter)
    register_pretty_printer(obj, pretty_printer)
    cseZdZ�fdd�Z�ZS)z.RegexpCollectionPrettyPrinter.RegexpSubprintercs.ttj|��|�||_||_t�|�|_dS�N)	�superr(�RegexpSubprinterr
�regexp�gen_printer�re�compile�compiled_re�rrr,r-��	__class__rr	r
�sz7RegexpCollectionPrettyPrinter.RegexpSubprinter.__init__)rrrr
�
__classcell__rrr2r	r+�sr+cstt|��|g�dSr))r*r(r
rr2rr	r
�sz&RegexpCollectionPrettyPrinter.__init__cCs|j�|�|||��dS)aoAdd a printer to the list.

        The printer is added to the end of the list.

        Arguments:
            name: The name of the subprinter.
            regexp: The regular expression, as a string.
            gen_printer: A function/method that given a value returns an
                object to pretty-print it.

        Returns:
            Nothing.
        N)r�appendr+r1rrr	�add_printer�sz)RegexpCollectionPrettyPrinter.add_printercCsTtj�|j�j}|s|jj}|s$dS|jD]$}|jr*|j�	|�r*|�
|�Sq*dS)z1Lookup the pretty-printer for the provided value.N)r�typesZget_basic_type�type�tagrrrr0�searchr-)rr�typenamer#rrr	r
�s
z&RegexpCollectionPrettyPrinter.__call__)
rrrrrr+r
r6r
r4rrr2r	r(�s
r(c@seZdZdd�Zdd�ZdS)�
_EnumInstancecCs||_||_dSr))�_EnumInstance__enumerators�_EnumInstance__val)r�enumeratorsrrrr	r
�sz_EnumInstance.__init__cCsxg}t|j�}d}|jD],\}}||@dkr|�|�||@}d}q|rR|dkr`|�d|�dt|j�d�|�fS)NFrTz<unknown: 0x%x>z	0x%x [%s]z | )�intr>r=r5�join)rZ	flag_list�vZ	any_foundZe_nameZe_valuerrr	�	to_string�s


z_EnumInstance.to_stringN)rrrr
rCrrrr	r<�sr<cs(eZdZdZ�fdd�Zdd�Z�ZS)�FlagEnumerationPrintera�A pretty-printer which can be used to print a flag-style enumeration.
    A flag-style enumeration is one where the enumerators are or'd
    together to create values.  The new printer will print these
    symbolically using '|' notation.  The printer must be registered
    manually.  This printer is most useful when an enum is flag-like,
    but has some overlap.  GDB's built-in printing will not handle
    this case, but this printer will attempt to.cstt|��|�d|_dS)NF)r*rDr
�initialized)rZ	enum_typer2rr	r
�szFlagEnumerationPrinter.__init__cCsl|jsRd|_t�|j�}g|_|��D]}|j�|j|jf�q&|jjdd�d�|j	rdt
|j|�SdSdS)NTcSs|dS�Nrr��xrrr	�<lambda>	�z1FlagEnumerationPrinter.__call__.<locals>.<lambda>)�key)rErZlookup_typerr?�fieldsr5�enumval�sortrr<)rr�flags�fieldrrr	r
szFlagEnumerationPrinter.__call__)rrrrr
r
r4rrr2r	rD�srDc@s eZdZdZdd�Zdd�ZdS)�NoOpScalarPrinterz1A no-op pretty printer that wraps a scalar value.cCs
||_dSr))�_NoOpScalarPrinter__value�r�valuerrr	r
szNoOpScalarPrinter.__init__cCs|jjdd�S)NT)�raw)rR�
format_string�rrrr	rCszNoOpScalarPrinter.to_stringN)rrrrr
rCrrrr	rQsrQc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�NoOpPointerReferencePrinterz9A no-op pretty printer that wraps a pointer or reference.cCs
||_dSr))�#_NoOpPointerReferencePrinter__valuerSrrr	r
sz$NoOpPointerReferencePrinter.__init__cCs|jjdd�S)NF)Z
deref_refs)rYrVrWrrr	rC!sz%NoOpPointerReferencePrinter.to_stringcCsdSrFrrWrrr	�num_children$sz(NoOpPointerReferencePrinter.num_childrencCsd|j��fS�NrT�rYZreferenced_value�rr%rrr	�child'sz!NoOpPointerReferencePrinter.childccsd|j��fVdSr[r\rWrrr	�children*sz$NoOpPointerReferencePrinter.childrenN)	rrrrr
rCrZr^r_rrrr	rXsrXc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�NoOpArrayPrinterz1A no-op pretty printer that wraps an array value.cs�||_|��\��|��dj}|��jtjkrx|����}t�	�fdd�|�}t�
�fdd�|�}d�tt|��d��|_
�|_dS)Nrcs
|j�kSr)�rMrG)�lowrr	rI<rJz+NoOpArrayPrinter.__init__.<locals>.<lambda>cs
|j�kSr)rarG)�highrr	rI>rJr)�_NoOpArrayPrinter__value�rangerLr8�target�coderZTYPE_CODE_ENUM�	itertools�	dropwhile�	takewhile�len�list�_NoOpArrayPrinter__low�_NoOpArrayPrinter__high)r�tyrTZ
range_typeZe_valuesr)rcrbr	r
1szNoOpArrayPrinter.__init__cCsdS�N�rrWrrr	rCDszNoOpArrayPrinter.to_stringcCsdS)NZarrayrrWrrr	�display_hintGszNoOpArrayPrinter.display_hintcCs|j|jdSrF)rnrmrWrrr	rZJszNoOpArrayPrinter.num_childrencCs|j||j|j|fSr))rmrdr]rrr	r^MszNoOpArrayPrinter.childccs,t|j|jd�D]}||j|fVqdSrF)rermrnrdr]rrr	r_PszNoOpArrayPrinter.childrenN)
rrrrr
rCrrrZr^r_rrrr	r`.sr`c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�NoOpStructPrinterz:A no-op pretty printer that wraps a struct or union value.cCs||_||_dSr))�_NoOpStructPrinter__ty�_NoOpStructPrinter__value)rrorTrrr	r
XszNoOpStructPrinter.__init__cCsdSrprrWrrr	rC\szNoOpStructPrinter.to_stringccs:|j��D]*}t|d�r
|jdur
|j|j|fVq
dS)NZbitpos)rtrLrrru)rrPrrr	r__szNoOpStructPrinter.childrenN)rrrrr
rCr_rrrr	rsUsrscCs�t�|�}|durn�|j��}|jr.t|�}n�|jtjkrFt||�}nj|j	rj|�
�}|j��}t||�}nF|jtjtjfvr�t
||�}n(|jtjtjtjfvr�t|�}nt|�}|S)z�Given a gdb.Value, wrap it in a pretty-printer.

    If a pretty-printer is found by the usual means, it is returned.
    Otherwise, VALUE will be wrapped in a no-op visualizer.N)rZdefault_visualizerr8Zstrip_typedefsZis_string_likerQrgZTYPE_CODE_ARRAYr`Z
is_array_likeZto_arrayZTYPE_CODE_STRUCTZTYPE_CODE_UNIONrsZ
TYPE_CODE_PTRZ
TYPE_CODE_REFZTYPE_CODE_RVALUE_REFrX)rT�resultrorrr	�make_visualizeres,



�
rwZbuiltincCst�|||�dSr))�_builtin_pretty_printersr6)rr,r#rrr	�add_builtin_pretty_printer�sry)F)rrZ	gdb.typesrhr.�objectrrr'r(ZValuePrinterr<rDrQrXr`rsrwrxryrrrr	�<module>s$ 
TC
'%