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

ɱZh:'�@s�ddlZddlmZddlmZddlmZmZddlm	Z	ddl
mZgaedd	��Z
ejj�e
�ed
d��Zedd
��ZGdd�de�ZGdd�de�Zedd��ZdS)�N�)�
in_gdb_thread)�client_bool_capability)�ABC�abstractmethod)�defaultdict)�contextmanagercCsgadS�N)�
all_variables)Zevent�r�'/usr/share/gdb/python/gdb/dap/varref.py�
clear_varssr
cks
dVdSr	r)�ignorerrr�_null(srcCs*|dur$d|vr$|dr$t�dd�St�S)z�Temporarily apply the DAP ValueFormat.

    This returns a new context manager that applies the given DAP
    ValueFormat object globally, then restores gdb's state when finished.N�hexzoutput-radix�)�gdbZwith_parameterr)Zvalue_formatrrr�apply_format-src@steZdZdZedd��Zedd��Zedd��Zdd	�Z	ed
d��Z
edd
��Zdd�Zedd��Z
edd��ZdS)�
BaseReferencez�Represent a variable or a scope.

    This class is just a base class, some methods must be implemented in
    subclasses.

    The 'ref' field can be used as the variablesReference in the protocol.
    cCs&t�|�tt�|_||_|��dS)z�Create a new variable reference with the given name.

        NAME is a string or None.  None means this does not have a
        name, e.g., the result of expression evaluation.N)r
�append�len�ref�name�reset_children��selfrrrr�__init__As

zBaseReference.__init__cCs2d|��r|jndi}|jdur.t|j�|d<|S)z�Return a dictionary that describes this object for DAP.

        The resulting object is a starting point that can be filled in
        further.  See the Scope or Variable types in the specZvariablesReferencerNr)�has_childrenrr�str)r�resultrrr�	to_objectNs
zBaseReference.to_objectcCsdS)z(Return True if this object has children.Fr�rrrrrYszBaseReference.has_childrencCsd|_i|_tdd��|_dS)z?Reset any cached information about the children of this object.NcSsdS)Nrrrrrr�<lambda>h�z.BaseReference.reset_children.<locals>.<lambda>)�children�by_namer�name_countsr!rrrr^szBaseReference.reset_childrencCsdS)z�Fetch one child of this variable.

        INDEX is the index of the child to fetch.
        This should return a tuple of the form (NAME, VALUE), where
        NAME is the name of the variable, and VALUE is a gdb.Value.Nr)r�indexrrr�fetch_one_childjszBaseReference.fetch_one_childcCsdS)z/Return the number of children of this variable.Nrr!rrr�child_countsszBaseReference.child_countcCs6||jvr2|j|d7<|dt|j|�}|S)Nrz #)r%r&rrrrr�
_compute_name�s
zBaseReference._compute_nameccs�|dkr|��}|jdur*dg|��|_t|||�D]T}|j|dur�|�|�\}}|�|�}t||�}||j|<||j|<|j|Vq8dS)z�Fetch children of this variable.

        START is the starting index.
        COUNT is the number to return, with 0 meaning return all.
        Returns an iterable of some kind.rN)r)r$�ranger(r*�VariableReferencer%)r�start�count�idxr�value�varrrr�fetch_children�s




zBaseReference.fetch_childrencCs(||jvr|j|Std|d��dS)zoFind a child of this variable, given its name.

        Returns the value of the child, or throws if not found.zno variable named '�'N)r%�	Exceptionrrrr�find_child_by_name�s

z BaseReference.find_child_by_nameN)�__name__�
__module__�__qualname__�__doc__rrr rrrr(r)r*r2r5rrrrr8s"







rcsbeZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�fdd�Z
edd��Z�Z
S)r,z:Concrete subclass of BaseReference that handles gdb.Value.r0cs$t��|�||_||_|��dS)z�Initializer.

        NAME is the name of this reference, see superclass.
        VALUE is a gdb.Value that holds the value.
        RESULT_NAME can be used to change how the simple string result
        is emitted in the result dictionary.N)�superr�result_namer0�
_update_value)rrr0r;��	__class__rrr�szVariableReference.__init__cCs8|��tj�|j�|_d|_|��r.d|_nd|_dS)N���)	rrZprintingZmake_visualizerr0�printer�child_cacherr.r!rrrr<�szVariableReference._update_valuecCs|j�|�|��dS)z'Assign VALUE to this object and update.N)r0�assignr<)rr0rrrrB�szVariableReference.assigncCst|jd�S)Nr$)�hasattrr@r!rrrr�szVariableReference.has_childrencCs |jdurt|j���|_|jSr	)rA�listr@r$r!rrr�cache_children�s
z VariableReference.cache_childrencCs`|jdurdS|jdkrZd}t|jtj�r@t|jd�r@|j��}|durTt|���}||_|jS)Nr?�num_children)	r.�
isinstancer@r�ValuePrinterrCrFrrE)rrFrrrr)�s

�
zVariableReference.child_countcs�t���}t|j���||j<|��}|durZt|jd�rR|j��dkrR||d<n||d<t	d�r�|j
j��j
tjkr�tt|j
��|d<t	d�r�t|j
j�|d<|S)	N�display_hintZarrayZindexedVariablesZnamedVariablesZsupportsMemoryReferencesZmemoryReferenceZsupportsVariableType�type)r:r rr@Z	to_stringr;r)rCrIrr0rJZstrip_typedefs�coderZ
TYPE_CODE_PTRr�int)rrrFr=rrr �s 

��
zVariableReference.to_objectcCsZt|jtj�r,t|jd�r,|j�|�\}}n|��|\}}t|tj�sRt�|�}||fS)N�child)rGr@rrHrCrMrEZValue)rr/r�valrrrr(�s�
z!VariableReference.fetch_one_child)r0)r6r7r8r9rr<rBrrEr)r rr(�
__classcell__rrr=rr,�s
	r,cCs,|d}|dks|tt�kr$td��t|S)zEGiven a variable reference, return the corresponding variable object.rrzinvalid variablesReference)rr
r4)rrrr�
find_variablesrP)rZstartuprZserverr�abcrr�collectionsr�
contextlibrr
r
ZeventsZcontZconnectrrrr,rPrrrr�<module>s"



s`