U
    Wd4                    @   s  d dl Z d dlZd dlZd dlZd dlZd dlZejd  dkrPeZe	Z
eZeZnG dd dZd dlm
Z
mZ dazd dlZ W n ek
r   daY nX dazd dlZ ee jdrdaW n ek
r   Y nX d	d
 Zdadd Zdd Zdd Zdd Zdd Zdd Zdd ZG dd deZG dd dZ dd Z!d d! Z"d"d# Z#G d$d% d%Z$d&d' Z%d(d) Z&G d*d+ d+Z'G d,d- d-Z(G d.d/ d/e(Z)G d0d1 d1e(Z*G d2d3 d3Z+G d4d5 d5Z,G d6d7 d7Z-G d8d9 d9Z.G d:d; d;Z/G d<d= d=Z0G d>d? d?eZ1d@dA Z2G dBdC dCZ3G dDdE dEZ4dFdG Z5G dHdI dIZ6G dJdK dKZ7G dLdM dMZ8G dNdO dOZ9G dPdQ dQZ:G dRdS dSZ;G dTdU dUeZ<G dVdW dWeZ=G dXdY dYZ>G dZd[ d[Z?G d\d] d]Z@G d^d_ d_eZAd`da ZBG dbdc dceAZCG ddde deeAZDG dfdg dgeAZEG dhdi dieAZFG djdk dkZGG dldm dmZHG dndo doZIG dpdq dqZJG drds dsZKG dtdu duZLG dvdw dweZMG dxdy dyeZNdaOG dzd{ d{eZPd|d} ZQG d~d deZRdd ZSdd ZTdd ZUdd ZVeV  dS )    N   c                   @   s   e Zd ZdZdd ZdS )Iteratora:  Compatibility mixin for iterators

        Instead of writing next() methods for iterators, write
        __next__() methods and use this mixin to make them work in
        Python 2 as well as Python 3.

        Idea stolen from the "six" documentation:
        <http://pythonhosted.org/six/#six.Iterator>
        c                 C   s   |   S N)__next__self r   I/usr/lib/x86_64-linux-gnu/../../share/gcc/python/libstdcxx/v6/printers.pynext<   s    zIterator.nextN)__name__
__module____qualname____doc__r
   r   r   r   r	   r   1   s   
r   )imapizipTFTypePrinterc                 C   sx   |   }d|j|f }zt|W S  tk
r6   Y nX | }t|r^|d jr^|d j}qt	dt
| |f qd S )Nz%s::%sr   zCannot find type %s::%s)strip_typedefstaggdblookup_typeRuntimeErrorfieldslenis_base_classtype
ValueErrorstr)Zorignametypsearchr   r   r   r	   	find_typeU   s    r    z__8::c                 G   s   d | ddd |D }zt|W S  tjk
r } zRtrt| kr|ddt d}zt|W  W Y  S  tjk
r   Y nX |W 5 d}~X Y nX dS )z7
    Lookup template specialization templ<args...>
    z{}<{}>, c                 S   s   g | ]}t |qS r   )r   ).0ar   r   r	   
<listcomp>m   s     z%lookup_templ_spec.<locals>.<listcomp>::   N)formatjoinr   r   error_versioned_namespacereplace)Ztemplargster   r   r	   lookup_templ_speci   s    r/   c                 C   s   d| krd|  } zt |d}W n   |d}Y nX | }zt| |W S  tjk
r } z\t| drt|dddr| dd	d
} zt| |W  W Y "S  tjk
r   Y nX W Y dS d}~X Y nX dS )z
    Lookup specialization of template NODENAME corresponding to CONTAINERTYPE.
    e.g. if NODENAME is '_List_node' and CONTAINERTYPE is std::list<int>
    then return the type std::_List_node<int>.
    Returns None if not found.
    r%   std::
value_typer   Zstdzstd::__cxx1998zstd::__debugZ__gnu_debugz::__cxx1998::r&   N)r    template_argumentr   r/   r   r)   is_member_of_namespacer+   )nodenameZcontainertypevaltyper.   r   r   r	   lookup_node_type~   s*    
 r6   c                 G   s@   t | tjkrt| } t| } |D ]}| |d r" dS q"dS )z
    Test whether a type is a member of one of the specified namespaces.
    The type can be specified as a string or a gdb.Type object.
    r%   TF)r   r   Typer   strip_versioned_namespace
startswith)r   Z
namespaces	namespacer   r   r	   r3      s    r3   c                 C   sD   t | tjkr| j} tr0tdt|f | dk	S td| | dk	S )z1Test if a type is a given template instantiation.z^std::(%s)?%s<.*>$Nz^std::%s<.*>$)r   r   r7   r   r*   rematch)xtemplate_namer   r   r	   is_specialization_of   s
    r?   c                 C   s   t r| t dS | S )N )r*   r+   typenamer   r   r	   r8      s    r8   c                 C   sR   t | } | dd} d}dD ]}| || d |} q|d }| |d |} | S )zARemove known inline namespaces from the canonical name of a type.std::__cxx11::r0   std::experimental::)Zfundamentals_v1Zfundamentals_v2r%   zfilesystem::zv1::)r8   r+   )type_strZexpt_nsZlfts_nsZfs_nsr   r   r	   strip_inline_namespaces   s    rF   c                 C   s<   d}g }z| | | W n   | Y S X |d7 }qdS )z,Return a type's template arguments as a listr   r&   N)appendr2   )type_objntemplate_argsr   r   r	   get_template_arg_list   s    
rK   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	SmartPtrIteratorz?An iterator for smart pointer types with a single 'child' valuec                 C   s
   || _ d S r   valr   rN   r   r   r	   __init__   s    zSmartPtrIterator.__init__c                 C   s   | S r   r   r   r   r   r	   __iter__   s    zSmartPtrIterator.__iter__c                 C   s$   | j d krtd | j  | _ }d|fS )Nzget()rN   StopIterationrO   r   r   r	   r      s    
zSmartPtrIterator.__next__Nr   r   r   r   rP   rQ   r   r   r   r   r	   rL      s   rL   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	SharedPointerPrinterzPrint a shared_ptr or weak_ptrc                 C   s   t || _|| _|d | _d S )N_M_ptr)r8   rB   rN   pointerr   rB   rN   r   r   r	   rP      s    
zSharedPointerPrinter.__init__c                 C   s
   t | jS r   )rL   rW   r   r   r   r	   children   s    zSharedPointerPrinter.childrenc                 C   sj   d}| j d d }|dkrL|d }|d }|dkr<d| }nd||d	 f }d
| jt| j jd|f S )NemptyZ_M_refcountZ_M_pir   Z_M_use_countZ_M_weak_countzexpired, weak count %dzuse count %d, weak count %dr&   z%s<%s> (%s))rN   rB   r   r   r2   )r   stateZ	refcountsZusecountZ	weakcountr   r   r	   	to_string   s    
zSharedPointerPrinter.to_stringNr   r   r   r   rP   rY   r\   r   r   r   r	   rU      s   rU   c                 C   s   | j  }|d js&tdt| j  | |d j }|j  }t|dkr^tdt| j  |d jdkrt|d S |d jr||d j S tdt| j  dS )zBReturn the tuple element stored in a _Tuple_impl<N, T> base class.z-Unsupported implementation for std::tuple: %sr   _M_head_implN)r   r   r   r   r   castr   r   )rN   basesZ	head_baser   r   r   r	   _tuple_impl_get   s    



rb   c                 C   sd   t t|j}| |krtd||j d j}| dkr\||j d j}| d8 } q4t|S )z5Return the result of std::get<n>(val) on a std::tuplez0Out of range index for std::get<N> on std::tupler   r&   )r   rK   r   r   r`   r   rb   )rI   rN   Z
tuple_sizenoder   r   r	   	tuple_get  s    
rd   c                 C   sd   | j  d j  }t|ds(t|dr6| d d }n$t|drJ| d }ntdt| td|S )z3Return the result of val.get() on a std::unique_ptrr   Z__uniq_ptr_dataZ__uniq_ptr_impl_M_ttuplez-Unsupported implementation for unique_ptr: %s)r   r   r   r?   r   r   rd   )rN   Z	impl_typeZtuple_memberr   r   r	   unique_ptr_get  s    


rg   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	UniquePointerPrinterzPrint a unique_ptrc                 C   s
   || _ d S r   rM   rX   r   r   r	   rP   '  s    zUniquePointerPrinter.__init__c                 C   s   t t| jS r   )rL   rg   rN   r   r   r   r	   rY   *  s    zUniquePointerPrinter.childrenc                 C   s   dt | jjd S )Nzstd::unique_ptr<%s>r   )r   rN   r   r2   r   r   r   r	   r\   -  s    zUniquePointerPrinter.to_stringNr]   r   r   r   r	   rh   $  s   rh   c                 C   s   | d j |  S )z8Returns the value held in a __gnu_cxx::__aligned_membuf.
_M_storage)addressr`   rW   dereference)Zbufr5   r   r   r	   get_value_from_aligned_membuf0  s    rl   c                 C   sn   zJ| j  d j}|dkr$| d W S |dkrH| j d}t| d |W S W n   Y nX tdt| j  dS )z-Returns the value held in an _List_node<_Val>r&   _M_datari   r   !Unsupported implementation for %sNr   r   r   r2   rl   r   r   rc   memberr5   r   r   r	   get_value_from_list_node4  s    
rr   c                   @   s8   e Zd ZdZG dd deZdd Zdd Zdd	 Zd
S )StdListPrinterzPrint a std::listc                   @   s$   e Zd Zdd Zdd Zdd ZdS )zStdListPrinter._iteratorc                 C   s"   || _ |d | _|j| _d| _d S N_M_nextr   )nodetypebaserj   headcountr   rv   rx   r   r   r	   rP   G  s    
z!StdListPrinter._iterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ   M  s    z!StdListPrinter._iterator.__iter__c                 C   sR   | j | jkrt| j | j }|d | _ | j}| jd | _t|}d| |fS )Nru   r&   [%d])rw   rx   rS   r`   rv   rk   ry   rr   )r   eltry   rN   r   r   r	   r   P  s    
z!StdListPrinter._iterator.__next__Nr   r   r   rP   rQ   r   r   r   r   r	   	_iteratorF  s   r~   c                 C   s   t || _|| _d S r   r8   rB   rN   rX   r   r   r	   rP   Z  s    
zStdListPrinter.__init__c                 C   s(   t d| jj }| || jd d S )N
_List_node_M_impl_M_noder6   rN   r   rW   r~   r   rv   r   r   r	   rY   ^  s    zStdListPrinter.childrenc                 C   s0   | j d d }|d |jkr&d| j S d| j S )Nr   r   ru   empty %s%s)rN   rj   rB   )r   Zheadnoder   r   r	   r\   b  s    
zStdListPrinter.to_stringN	r   r   r   r   r   r~   rP   rY   r\   r   r   r   r	   rs   C  s
   rs   c                   @   s   e Zd Zdd Zdd ZdS )NodeIteratorPrinterc                 C   s$   || _ || _|| _t||j| _d S r   )rN   rB   contnamer6   r   rv   )r   rB   rN   r   r4   r   r   r	   rP   i  s    zNodeIteratorPrinter.__init__c                 C   s:   | j d sd| j S | j d | j  }tt|S )Nr   z(non-dereferenceable iterator for std::%s)rN   r   r`   rv   rW   rk   r   rr   r   rc   r   r   r	   r\   o  s    

zNodeIteratorPrinter.to_stringN)r   r   r   rP   r\   r   r   r   r	   r   h  s   r   c                   @   s   e Zd ZdZdd ZdS )StdListIteratorPrinterzPrint std::list::iteratorc                 C   s   t | ||dd d S )Nlistr   r   rP   rX   r   r   r	   rP   x  s    zStdListIteratorPrinter.__init__Nr   r   r   r   rP   r   r   r   r	   r   u  s   r   c                   @   s   e Zd ZdZdd ZdS )StdFwdListIteratorPrinterz!Print std::forward_list::iteratorc                 C   s   t | ||dd d S )Nforward_list_Fwd_list_noder   rX   r   r   r	   rP   ~  s    z"StdFwdListIteratorPrinter.__init__Nr   r   r   r   r	   r   {  s   r   c                   @   s8   e Zd ZdZG dd deZdd Zdd Zdd	 Zd
S )StdSlistPrinterzPrint a __gnu_cxx::slistc                   @   s$   e Zd Zdd Zdd Zdd ZdS )zStdSlistPrinter._iteratorc                 C   s   || _ |d d | _d| _d S )N_M_headru   r   rv   rw   ry   rz   r   r   r	   rP     s    z"StdSlistPrinter._iterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ     s    z"StdSlistPrinter._iterator.__iter__c                 C   sL   | j dkrt| j | j }|d | _ | j}| jd | _d| |d fS )Nr   ru   r&   r{   rm   )rw   rS   r`   rv   rk   ry   )r   r|   ry   r   r   r	   r     s    

z"StdSlistPrinter._iterator.__next__Nr}   r   r   r   r	   r~     s   r~   c                 C   s
   || _ d S r   rM   rX   r   r   r	   rP     s    zStdSlistPrinter.__init__c                 C   s    t d| jj}| | | jS )N__gnu_cxx::_Slist_node)r6   rN   r   r~   rW   r   r   r   r	   rY     s    zStdSlistPrinter.childrenc                 C   s   | j d d dkrdS dS )Nr   ru   r   zempty __gnu_cxx::slistz__gnu_cxx::slistrM   r   r   r   r	   r\     s    zStdSlistPrinter.to_stringNr   r   r   r   r	   r     s
   r   c                   @   s    e Zd ZdZdd Zdd ZdS )StdSlistIteratorPrinterz Print __gnu_cxx::slist::iteratorc                 C   s
   || _ d S r   rM   rX   r   r   r	   rP     s    z StdSlistIteratorPrinter.__init__c                 C   s<   | j d sdS td| j j }t| j d | d S )Nr   z1non-dereferenceable iterator for __gnu_cxx::slistr   rm   )rN   r6   r   rW   r   r`   rk   r   r   r   r	   r\     s    
z!StdSlistIteratorPrinter.to_stringNr   r   r   r   rP   r\   r   r   r   r	   r     s   r   c                   @   s@   e Zd ZdZG dd deZdd Zdd Zdd	 Zd
d Z	dS )StdVectorPrinterzPrint a std::vectorc                   @   s$   e Zd Zdd Zdd Zdd ZdS )zStdVectorPrinter._iteratorc                 C   sb   || _ |rL|d | _|d | _|d | _|d | _| j j}d|j | _n|| _|| _d| _	d S )N_M_p	_M_offset   r   )
bitvecitemsofinishfork   r   sizeofisizery   )r   startr   r   ityper   r   r	   rP     s    



z#StdVectorPrinter._iterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ     s    z#StdVectorPrinter._iterator.__iter__c                 C   s   | j }| j d | _ | jr| j| jkr4| j| jkr4tt| j d| j> @ }| jd | _| j| j	krv| jd | _d| _d| |fS | j| jkrt| j }| jd | _d| |fS d S )Nr&   r   r{   )
ry   r   r   r   r   r   rS   boolrk   r   )r   ry   r|   r   r   r	   r     s     
z#StdVectorPrinter._iterator.__next__Nr}   r   r   r   r	   r~     s   r~   c                 C   s*   t || _|| _|jdjtjk| _d S Nr   )	r8   rB   rN   r   r2   coder   TYPE_CODE_BOOLis_boolrX   r   r   r	   rP     s    
zStdVectorPrinter.__init__c                 C   s$   |  | jd d | jd d | jS )Nr   _M_start	_M_finish)r~   rN   r   r   r   r   r	   rY     s    zStdVectorPrinter.childrenc           
      C   s   | j d d }| j d d }| j d d }| jr| j d d d }| j d d d }| j d d d }| j d d d }| j}d|j }|| ||| d   | }|||  }	d	| jt|t|	f S d
| jt|| t|| f S d S )Nr   r   r   Z_M_end_of_storager   r   r   r&   z"%s<bool> of length %d, capacity %dz%s of length %d, capacity %d)rN   r   rk   r   r   rB   int)
r   r   r   endr   r   r   ZbllengthZcapacityr   r   r	   r\     s$    

zStdVectorPrinter.to_stringc                 C   s   dS Narrayr   r   r   r   r	   display_hint  s    zStdVectorPrinter.display_hintN)
r   r   r   r   r   r~   rP   rY   r\   r   r   r   r   r	   r     s   %r   c                   @   s    e Zd ZdZdd Zdd ZdS )StdVectorIteratorPrinterzPrint std::vector::iteratorc                 C   s
   || _ d S r   rM   rX   r   r   r	   rP     s    z!StdVectorIteratorPrinter.__init__c                 C   s    | j d sdS t| j d  S )NZ
_M_currentz,non-dereferenceable iterator for std::vectorrN   r   rk   r   r   r   r	   r\     s    
z"StdVectorIteratorPrinter.to_stringNr   r   r   r   r	   r     s   r   c                   @   s8   e Zd ZdZG dd deZdd Zdd Zdd	 Zd
S )StdTuplePrinterzPrint a std::tuplec                   @   s0   e Zd Zedd Zdd Zdd Zdd Zd	S )
zStdTuplePrinter._iteratorc                 C   sN   t | dkr"t| d jdrBdS n t | dkr2dS t | dkrBdS tdd S )Nr   r&   Z__tuple_baseTr   Fz4Top of tuple tree does not consist of a single node.)r   r?   r   r   )nodesr   r   r	   _is_nonempty_tuple  s    z,StdTuplePrinter._iterator._is_nonempty_tuplec                 C   s:   || _ | j j }| |r0| j |d j| _ d| _d S r   )rx   r   r   r   r`   ry   )r   rx   r   r   r   r	   rP     s
    
z"StdTuplePrinter._iterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ     s    z"StdTuplePrinter._iterator.__iter__c                 C   s   | j s
t| j j }t|dkr&tt|dkr:tdt|dkr`| j |d j}d | _ n&| j |d j}| j |d j| _ | jd | _|j }t|dk s|d jdkrd| j |fS d| j |d fS d S )Nr   r   z/Cannot parse more than 2 nodes in a tuple tree.r&   r_   r{   )	rx   rS   r   r   r   r   r`   ry   r   )r   r   implr   r   r   r	   r   !  s"    	
z"StdTuplePrinter._iterator.__next__N)r   r   r   staticmethodr   rP   rQ   r   r   r   r   r	   r~     s
   

r~   c                 C   s   t || _|| _d S r   r   rX   r   r   r	   rP   J  s    
zStdTuplePrinter.__init__c                 C   s   |  | jS r   )r~   rN   r   r   r   r	   rY   N  s    zStdTuplePrinter.childrenc                 C   s(   t | jj dkrd| j S d| j S )Nr   r   z%s containing)r   rN   r   r   rB   r   r   r   r	   r\   Q  s    
zStdTuplePrinter.to_stringNr   r   r   r   r	   r     s
   Cr   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )StdStackOrQueuePrinterz Print a std::stack or std::queuec                 C   s   t || _t|d | _d S )Nc)r8   rB   r   default_visualizer
visualizerrX   r   r   r	   rP   Y  s    
zStdStackOrQueuePrinter.__init__c                 C   s
   | j  S r   )r   rY   r   r   r   r	   rY   ]  s    zStdStackOrQueuePrinter.childrenc                 C   s   d| j | j f S )Nz%s wrapping: %s)rB   r   r\   r   r   r   r	   r\   `  s    z StdStackOrQueuePrinter.to_stringc                 C   s   t | jdr| j S d S )Nr   )hasattrr   r   r   r   r   r	   r   d  s    
z#StdStackOrQueuePrinter.display_hintN)r   r   r   r   rP   rY   r\   r   r   r   r   r	   r   V  s
   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )RbtreeIteratorzf
    Turn an RB-tree-based container (std::map, std::set etc.) into
    a Python iterable object.
    c                 C   s2   |d d d | _ |d d d d | _d| _d S )Nre   r   Z_M_node_countZ	_M_header_M_leftr   )sizerc   ry   )r   Zrbtreer   r   r	   rP   o  s    zRbtreeIterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ   t  s    zRbtreeIterator.__iter__c                 C   s
   t | jS r   )r   r   r   r   r   r	   __len__w  s    zRbtreeIterator.__len__c                 C   s   | j | jkrt| j}| j d | _ | j | jk r| j}| d rh| d }| d r| d }qLnB| d }|| d kr|}| d }qt| d |kr|}|| _|S )Nr&   Z_M_rightr   Z	_M_parent)ry   r   rS   rc   rk   )r   resultrc   parentr   r   r	   r   z  s$    zRbtreeIterator.__next__N)r   r   r   r   rP   rQ   r   r   r   r   r   r	   r   i  s
   r   c                 C   sn   zJ| j  d j}|dkr$| d W S |dkrH| j d}t| d |W S W n   Y nX tdt| j  dS )z0Returns the value held in an _Rb_tree_node<_Val>r&   Z_M_value_fieldri   r   rn   Nro   rp   r   r   r	   get_value_from_Rb_tree_node  s    
r   c                   @   s    e Zd ZdZdd Zdd ZdS )StdRbtreeIteratorPrinterz2Print std::map::iterator, std::set::iterator, etc.c                 C   s"   || _ td| j j}| | _d S N_Rb_tree_node)rN   r6   r   rW   	link_type)r   rB   rN   rv   r   r   r	   rP     s    z!StdRbtreeIteratorPrinter.__init__c                 C   s0   | j d sdS | j d | j }tt|S )Nr   z6non-dereferenceable iterator for associative container)rN   r`   r   rk   r   r   r   r   r   r	   r\     s    
z"StdRbtreeIteratorPrinter.to_stringNr   r   r   r   r	   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )StdDebugIteratorPrinterz,Print a debug enabled version of an iteratorc                 C   s
   || _ d S r   rM   rX   r   r   r	   rP     s    z StdDebugIteratorPrinter.__init__c                 C   sb   t d}| jjd}| j|d }|s<t| j|S | jd |d krRdS t| j|S )Nz __gnu_debug::_Safe_iterator_baser   Z_M_sequenceZ
_M_versionzinvalid iterator)r   r   rN   r   r2   r`   r   )r   Z	base_typer   Zsafe_seqr   r   r	   r\     s    
z!StdDebugIteratorPrinter.to_stringNr   r   r   r   r	   r     s   r   c                 C   s   | dkrdS d|  S )zDReturn either "1 element" or "N elements" depending on the argument.r&   z	1 elementz%d elementsr   )numr   r   r	   num_elements  s    r   c                   @   s@   e Zd ZdZG dd deZdd Zdd Zdd	 Zd
d Z	dS )StdMapPrinterz!Print a std::map or std::multimapc                   @   s$   e Zd Zdd Zdd Zdd ZdS )zStdMapPrinter._iterc                 C   s   || _ d| _|| _d S r   rbiterry   r   r   r   r   r   r   r	   rP     s    zStdMapPrinter._iter.__init__c                 C   s   | S r   r   r   r   r   r	   rQ     s    zStdMapPrinter._iter.__iter__c                 C   sh   | j d dkr@t| j}|| j }t|}|| _|d }n
| jd }d| j  |f}| j d | _ |S )Nr   r   firstsecondr{   r&   )ry   r
   r   r`   r   rk   r   pair)r   rI   r   r   r   r   r	   r     s    


zStdMapPrinter._iter.__next__Nr}   r   r   r   r	   _iter  s   r   c                 C   s   t || _|| _d S r   r   rX   r   r   r	   rP     s    
zStdMapPrinter.__init__c                 C   s   d| j ttt| jf S N
%s with %srB   r   r   r   rN   r   r   r   r	   r\     s    zStdMapPrinter.to_stringc                 C   s$   t d| jj }| t| j|S r   r6   rN   r   rW   r   r   r   r   r   r	   rY     s    zStdMapPrinter.childrenc                 C   s   dS Nmapr   r   r   r   r	   r     s    zStdMapPrinter.display_hintN
r   r   r   r   r   r   rP   r\   rY   r   r   r   r   r	   r     s   r   c                   @   s8   e Zd ZdZG dd deZdd Zdd Zdd	 Zd
S )StdSetPrinterz!Print a std::set or std::multisetc                   @   s$   e Zd Zdd Zdd Zdd ZdS )zStdSetPrinter._iterc                 C   s   || _ d| _|| _d S r   r   r   r   r   r	   rP     s    zStdSetPrinter._iter.__init__c                 C   s   | S r   r   r   r   r   r	   rQ     s    zStdSetPrinter._iter.__iter__c                 C   s@   t | j}|| j }t|}d| j |f}| jd | _|S )Nr{   r&   )r
   r   r`   r   rk   r   ry   )r   r   r   r   r   r	   r     s    
zStdSetPrinter._iter.__next__Nr}   r   r   r   r	   r     s   r   c                 C   s   t || _|| _d S r   r   rX   r   r   r	   rP     s    
zStdSetPrinter.__init__c                 C   s   d| j ttt| jf S r   r   r   r   r   r	   r\   
  s    zStdSetPrinter.to_stringc                 C   s$   t d| jj }| t| j|S r   r   r   r   r   r	   rY     s    zStdSetPrinter.childrenN)	r   r   r   r   r   r   rP   r\   rY   r   r   r   r	   r     s
   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	StdBitsetPrinterzPrint a std::bitsetc                 C   s   t || _|| _d S r   r   rX   r   r   r	   rP     s    
zStdBitsetPrinter.__init__c                 C   s
   d| j  S )Nr   rA   r   r   r   r	   r\     s    zStdBitsetPrinter.to_stringc           	      C   s   z| j d }W n   g  Y S X |j}|jtjkr>| j}n|g}|j}|j| }g }d}||k r|| }d}|dkr|d@ dkr|d|| d |  df |d }|d? }qp|d }q\|S )NZ_M_wr   r&   r{   r   )rN   r   r   r   TYPE_CODE_ARRAYtargetr   rG   )	r   ZwordsZwtypeZtsizeZnwordsr   Zbytewbitr   r   r	   rY     s,    



zStdBitsetPrinter.childrenN)r   r   r   r   rP   r\   rY   r   r   r   r	   r     s   r   c                   @   s@   e Zd ZdZG dd deZdd Zdd Zdd	 Zd
d Z	dS )StdDequePrinterzPrint a std::dequec                   @   s$   e Zd Zdd Zdd Zdd ZdS )zStdDequePrinter._iterc                 C   s(   || _ || _|| _|| _|| _d| _d S r   )rc   pr   lastbuffer_sizery   )r   rc   r   r   r   r   r   r   r	   rP   D  s    zStdDequePrinter._iter.__init__c                 C   s   | S r   r   r   r   r   r	   rQ   L  s    zStdDequePrinter._iter.__iter__c                 C   sr   | j | jkrtd| j | j  f}| jd | _| j d | _ | j | jkrn| jd | _| jd | _ | j | j | _|S )Nr{   r&   r   )r   r   rS   ry   rk   r   rc   r   )r   r   r   r   r	   r   O  s    zStdDequePrinter._iter.__next__Nr}   r   r   r   r	   r   C  s   r   c                 C   sH   t || _|| _|jd| _| jj}|dk r>td| | _nd| _d S )Nr   i   r&   )	r8   rB   rN   r   r2   Zelttyper   r   r   )r   rB   rN   r   r   r   r	   rP   a  s    
zStdDequePrinter.__init__c                 C   sx   | j d d }| j d d }|d |d  d }|d |d  }|d |d  }| j| | | }d	| jtt|f S )
Nr   r   r   r   r&   _M_last_M_cur_M_firstr   )rN   r   rB   r   long)r   r   r   Zdelta_nZdelta_sZdelta_er   r   r   r	   r\   k  s    zStdDequePrinter.to_stringc                 C   s@   | j d d }| j d d }| |d |d |d |d | jS )Nr   r   r   r   r   r   )rN   r   r   )r   r   r   r   r   r	   rY   w  s     zStdDequePrinter.childrenc                 C   s   dS r   r   r   r   r   r	   r   }  s    zStdDequePrinter.display_hintNr   r   r   r   r	   r   @  s   
r   c                   @   s    e Zd ZdZdd Zdd ZdS )StdDequeIteratorPrinterzPrint std::deque::iteratorc                 C   s
   || _ d S r   rM   rX   r   r   r	   rP     s    z StdDequeIteratorPrinter.__init__c                 C   s    | j d sdS t| j d  S )Nr   z+non-dereferenceable iterator for std::dequer   r   r   r   r	   r\     s    
z!StdDequeIteratorPrinter.to_stringNr   r   r   r   r	   r     s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	StdStringPrinterz&Print a std::basic_string of some kindc                 C   s   || _ |ddk| _d S )Nz::__cxx11::basic_stringr^   )rN   find
new_stringrX   r   r   r	   rP     s    zStdStringPrinter.__init__c                 C   s   | j j}|jtjkr| }| j d d }| jrL| j d }||j }n<|	  }t
t|d  }||d }| d }t|dr|j|dS |j|dS )	NZ_M_dataplusr   Z_M_string_lengthz::_Repr&   Z	_M_lengthlazy_stringr   )rN   r   r   r   TYPE_CODE_REFr   r   r`   r   unqualifiedr   r   rW   rk   r   r   string)r   r   ptrr   ZrealtypeZreptypeheaderr   r   r	   r\     s    

zStdStringPrinter.to_stringc                 C   s   dS Nr   r   r   r   r   r	   r     s    zStdStringPrinter.display_hintNr   r   r   r   rP   r\   r   r   r   r   r	   r     s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )Tr1HashtableIteratorc                 C   sf   |d | _ d| _|d | _t|jd | _d| _| j| jkrb| j | j | _| jrTqb| jd | _q2d S )NZ
_M_bucketsr   Z_M_bucket_countZ_Noder&   )bucketsbucketbucket_countr    r   rW   	node_typerc   )r   	hashtabler   r   r	   rP     s    

zTr1HashtableIterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ     s    zTr1HashtableIterator.__iter__c                 C   s   | j dkrt| j | j}| d }| d | _ | j dkr|| jd | _| j| jkr|| j| j | _ | j rnq|| jd | _qL|S )Nr   Z_M_vru   r&   )rc   rS   r`   r   rk   r   r   r   )r   rc   r   r   r   r	   r     s    

zTr1HashtableIterator.__next__Nr}   r   r   r   r	   r     s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )StdHashtableIteratorc                 C   sR   |d d | _ |jd}|jdd}tdt||r>dnd}| | _d S )	NZ_M_before_begin_M_nxtr&   	   r   zstd::__detail::_Hash_nodetrueZfalse)rc   r   r2   r/   r   rW   r   )r   r   r5   cachedr   r   r   r	   rP     s    

zStdHashtableIterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ     s    zStdHashtableIterator.__iter__c                 C   sR   | j dkrt| j | j }|d | _ |d j}||jd }| S )Nr   r   ri   )	rc   rS   r`   r   rk   rj   r   r2   rW   )r   r|   valptrr   r   r	   r     s    


zStdHashtableIterator.__next__Nr}   r   r   r   r	   r     s   r   c                   @   s<   e Zd ZdZdd Zdd Zdd Zedd	 Zd
d Z	dS )Tr1UnorderedSetPrinterz0Print a std::unordered_set or tr1::unordered_setc                 C   s   t || _|| _d S r   r   rX   r   r   r	   rP     s    
zTr1UnorderedSetPrinter.__init__c                 C   s   | j dr| jS | jd S Nstd::tr1Z_M_hrB   r9   rN   r   r   r   r	   r     s    z Tr1UnorderedSetPrinter.hashtablec                 C   s   |   d }d| jt|f S NZ_M_element_countr   r   rB   r   r   ry   r   r   r	   r\     s    z Tr1UnorderedSetPrinter.to_stringc                 C   s   d|  S Nr{   r   ir   r   r	   format_count  s    z#Tr1UnorderedSetPrinter.format_countc                 C   s@   t | jt }| jdr.t|t|  S t|t	|  S Nr  )
r   r  	itertoolsry   rB   r9   r   r   r   r   )r   counterr   r   r	   rY     s    zTr1UnorderedSetPrinter.childrenN)
r   r   r   r   rP   r   r\   r   r  rY   r   r   r   r	   r    s   
r  c                   @   s\   e Zd ZdZdd Zdd Zdd Zedd	 Zed
d Z	edd Z
dd Zdd ZdS )Tr1UnorderedMapPrinterz0Print a std::unordered_map or tr1::unordered_mapc                 C   s   t || _|| _d S r   r   rX   r   r   r	   rP     s    
zTr1UnorderedMapPrinter.__init__c                 C   s   | j dr| jS | jd S r  r  r   r   r   r	   r     s    z Tr1UnorderedMapPrinter.hashtablec                 C   s   |   d }d| jt|f S r  r  r  r   r   r	   r\     s    z Tr1UnorderedMapPrinter.to_stringc                 c   s   | D ]}|D ]
}|V  qqd S r   r   )r   r|   r  r   r   r	   flatten
  s    zTr1UnorderedMapPrinter.flattenc                 C   s   | d | d fS Nr   r   r   )r|   r   r   r	   
format_one  s    z!Tr1UnorderedMapPrinter.format_onec                 C   s   d|  S r	  r   r
  r   r   r	   r    s    z#Tr1UnorderedMapPrinter.format_countc                 C   sd   t | jt }| jdr@| t | jt| 	 }t
||S | t | jt| 	 }t
||S r  )r   r  r  ry   rB   r9   r  r  r   r   r   r   )r   r  datar   r   r	   rY     s    
zTr1UnorderedMapPrinter.childrenc                 C   s   dS r   r   r   r   r   r	   r   #  s    z#Tr1UnorderedMapPrinter.display_hintN)r   r   r   r   rP   r   r\   r   r  r  r  rY   r   r   r   r   r	   r    s   


r  c                   @   s8   e Zd ZdZG dd deZdd Zdd Zdd	 Zd
S )StdForwardListPrinterzPrint a std::forward_listc                   @   s$   e Zd Zdd Zdd Zdd ZdS )zStdForwardListPrinter._iteratorc                 C   s   || _ |d | _d| _d S rt   r   rz   r   r   r	   rP   *  s    
z(StdForwardListPrinter._iterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ   /  s    z(StdForwardListPrinter._iterator.__iter__c                 C   sl   | j dkrt| j | j }|d | _ | j}| jd | _|d j}||jd	 }d| | fS )Nr   ru   r&   ri   r{   )
rw   rS   r`   rv   rk   ry   rj   r   r2   rW   )r   r|   ry   r  r   r   r	   r   2  s    


z(StdForwardListPrinter._iterator.__next__Nr}   r   r   r   r	   r~   )  s   r~   c                 C   s   || _ t|| _d S r   )rN   r8   rB   rX   r   r   r	   rP   =  s    zStdForwardListPrinter.__init__c                 C   s(   t d| jj }| || jd d S )Nr   r   r   r   r   r   r   r	   rY   A  s    zStdForwardListPrinter.childrenc                 C   s*   | j d d d dkr d| j S d| j S )Nr   r   ru   r   r   r   )rN   rB   r   r   r   r	   r\   E  s    
zStdForwardListPrinter.to_stringNr   r   r   r   r	   r  &  s
   r  c                   @   sB   e Zd ZdZdddZdd ZG dd deZd	d
 Zdd Z	dS )SingleObjContainerPrinterz7Base class for printers of containers of single objectsNc                 C   s   || _ || _|| _d S r   )contained_valuer   hint)r   rN   Zvizr  r   r   r	   rP   M  s    z"SingleObjContainerPrinter.__init__c                 C   s(   t st|S tjtj |p&t|S )z4Return TYPE as a string after applying type printers)_use_type_printingr   r   typesapply_type_recognizersget_type_recognizers)r   r   r   r   r	   
_recognizeR  s    z$SingleObjContainerPrinter._recognizec                   @   s$   e Zd Zdd Zdd Zdd ZdS )z$SingleObjContainerPrinter._containedc                 C   s
   || _ d S r   rM   rO   r   r   r	   rP   [  s    z-SingleObjContainerPrinter._contained.__init__c                 C   s   | S r   r   r   r   r   r	   rQ   ^  s    z-SingleObjContainerPrinter._contained.__iter__c                 C   s"   | j d krt| j }d | _ d|fS )Nz[contained value]rR   )r   Zretvalr   r   r	   r   a  s
    
z-SingleObjContainerPrinter._contained.__next__Nr}   r   r   r   r	   
_containedZ  s   r  c                 C   s6   | j d kr| d S t| jdr*| j S | | j S )NrY   )r  r  r   r   rY   r   r   r   r	   rY   h  s
    


z"SingleObjContainerPrinter.childrenc                 C   s(   t | jdr"t | jdr"| j S | jS )NrY   r   )r   r   r   r  r   r   r   r	   r   o  s    
z&SingleObjContainerPrinter.display_hint)N)
r   r   r   r   rP   r  r   r  rY   r   r   r   r   r	   r  J  s   
r  c                 C   sN   |   j} tjd dkr"t| } nt| } zt| jj	W S    Y dS X dS )z>Find the name of the function referred to by the gdb.Value f, r   r   N)
rk   rj   sysversion_infor   r   r   block_for_pcfunctionr   )fr   r   r	   function_pointer_to_nameu  s    

r$  c                       s(   e Zd ZdZ fddZdd Z  ZS )StdExpAnyPrinterz*Print a std::any or std::experimental::anyc                    sL  t || _tdd| jd| _|| _d | _d }d }| jd }|dkr6t|}|s`td| j d|}t	||}|std| j |
d}	d	|	krtd
ttd	 |
d}	t|	}
|
d| _d }d|	kr| jd d j}n(d|	kr
| jd d }ntd| j || j  }t|}tt| || d S )Nz&^std::experimental::fundamentals_v\d::rD   r&   Z
_M_managerr   zInvalid function pointer in %szi({0}::_Manager_\w+<.*>)::_S_manage\((enum )?{0}::_Op, (const {0}|{0} const) ?\*, (union )?{0}::_Arg ?\*\)zUnknown manager function in %szstd::stringzstd::string(?!\w)z::_Manager_internalri   Z	_M_bufferz::_Manager_externalrV   )r8   rB   r;   subrN   contained_typer$  r   r'   r<   groupr   r   r   r   r2   rj   r`   rW   rk   r   superr%  rP   )r   rB   rN   r  r   ZmgrfuncZrxmZmgrnameZmgrtyper  	__class__r   r	   rP     s:    




"


zStdExpAnyPrinter.__init__c                 C   sT   | j d krd| j S d| j }t| jdr8|| j  S | | j }|tt| S )N%s [no contained value]z%s containing rY   )r'  rB   r   r   r\   r  r8   r   )r   descr5   r   r   r	   r\     s    


zStdExpAnyPrinter.to_stringr   r   r   r   rP   r\   __classcell__r   r   r,  r	   r%    s   #r%  c                       s(   e Zd ZdZ fddZdd Z  ZS )StdExpOptionalPrinterz4Print a std::optional or std::experimental::optionalc                    s   |  |jd}t|}tdd| |d| _|d }| jdrR|d }|}n*|d }|d }z|d }W n   Y nX t	|}|sd }t
t| || d S )	Nr   z0^std::(experimental::|)(fundamentals_v\d::|)(.*)zstd::\1\3<%s>r&   
_M_payloadzstd::experimental
_M_engaged_M_value)r  r   r2   r8   r;   r&  rB   r9   r   r   r)  r2  rP   )r   rB   rN   r5   ZpayloadZengagedr  r   r,  r   r	   rP     s"    
zStdExpOptionalPrinter.__init__c                 C   s:   | j d krd| j S t| jdr4d| j| j f S | jS )Nr.  rY   z%s containing %s)r  rB   r   r   r\   r   r   r   r	   r\     s    

zStdExpOptionalPrinter.to_stringr0  r   r   r,  r	   r2    s   r2  c                       s(   e Zd ZdZ fddZdd Z  ZS )StdVariantPrinterzPrint a std::variantc                    s   t |j}t| _d jd fdd|D f  _|d  _ jt|kr`d  _d }d }n@|t j  _|d d d j	}|
 j  }t|}tt ||d	 d S )
Nz%s<%s>r!   c                    s   g | ]}  |qS r   )r  )r"   Zaltr   r   r	   r$     s     z.StdVariantPrinter.__init__.<locals>.<listcomp>Z_M_indexZ_M_ur   ri   r   )rK   r   r8   rB   r(   indexr   r'  r   rj   r`   rW   rk   r   r   r)  r6  rP   )r   rB   rN   Zalternativesr  r   addrr,  r   r	   rP     s    

$

zStdVariantPrinter.__init__c                 C   sH   | j d krd| j S t| jdr8d| j| j| j f S d| j| jf S )Nr.  rY   z%s [index %d] containing %sz%s [index %d])r  rB   r   r   r7  r\   r   r   r   r	   r\     s    


zStdVariantPrinter.to_stringr0  r   r   r,  r	   r6    s   r6  c                       s(   e Zd ZdZ fddZdd Z  ZS )StdNodeHandlePrinterzPrint a container node handlec                    s   |j d| _|j dd}t|jd| _|j d| jk| _|d }|r~| jrbt| }nt	|d | j}t
|}nd }d }|d }|d r|d	 nd | _tt| ||d
 d S )Nr&   r   r   r   rV   ri   Z_M_allocr4  r3  r   )r   r2   r1   r?   r   is_rb_tree_nodeis_map_noder   rk   rl   r   r   Zallocr)  r9  rP   )r   rB   rN   rv   Znodeptrr  r   Zoptallocr,  r   r	   rP     s&    zStdNodeHandlePrinter.__init__c                 C   sf   d}| j s|d7 }| jr"|d7 }n|d7 }| jrZ|d7 }t| jdrVd|| j f S |S d| S d S )	Nznode handle for z
unordered r   setz with elementrY   z%s = %sr   )r:  r;  r  r   r   r\   )r   r/  r   r   r	   r\     s    
zStdNodeHandlePrinter.to_stringr0  r   r   r,  r	   r9    s   r9  c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	StdExpStringViewPrinterzFPrint a std::basic_string_view or std::experimental::basic_string_viewc                 C   s
   || _ d S r   rM   rX   r   r   r	   rP   "  s    z StdExpStringViewPrinter.__init__c                 C   s6   | j d }| j d }t|dr*|j|dS |j|dS )NZ_M_strZ_M_lenr   r   )rN   r   r   r   )r   r   r   r   r   r	   r\   %  s
    


z!StdExpStringViewPrinter.to_stringc                 C   s   dS r   r   r   r   r   r	   r   ,  s    z$StdExpStringViewPrinter.display_hintNr   r   r   r   r	   r=    s   r=  c                   @   s@   e Zd ZdZdd Zdd Zdd ZG dd	 d	eZd
d Z	dS )StdExpPathPrinterz+Print a std::experimental::filesystem::pathc                 C   sB   || _ || _| j d d d }| j d d d }t|| | _d S )N_M_cmptsr   r   r   )rN   rB   r   	num_cmpts)r   rB   rN   r   r   r   r   r	   rP   2  s
    zStdExpPathPrinter.__init__c                 C   s:   t | jd }|dd  dkr"dS |dd  dkr6dS d S )NZ_M_type	_Root_dirroot-directory
_Root_name	root-name)r   rN   r   r-   r   r   r	   
_path_type9  s    zStdExpPathPrinter._path_typec                 C   s8   d| j d  }| jdkr0|  }|r0d||f }d| S )Nr   _M_pathnamer   %s [%s]z!experimental::filesystem::path %s)rN   r@  rH  r   pathr-   r   r   r	   r\   A  s    
zStdExpPathPrinter.to_stringc                   @   s$   e Zd Zdd Zdd Zdd ZdS )zStdExpPathPrinter._iteratorc                 C   s,   || _ |d d | _|d d | _d| _d S )Nr   r   r   r   )pathtyper   r   ry   )r   ZcmptsrM  r   r   r	   rP   J  s    z$StdExpPathPrinter._iterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ   P  s    z$StdExpPathPrinter._iterator.__iter__c                 C   sd   | j | jkrt| j  }| j}| jd | _| j d | _ |d }t| j| }|sX|}d| |fS Nr&   rI  z[%s])r   r   rS   rk   ry   r>  rM  rH  r   r   ry   rL  r-   r   r   r	   r   S  s    
z$StdExpPathPrinter._iterator.__next__Nr}   r   r   r   r	   r~   I  s   r~   c                 C   s   |  | jd | jS )Nr?  )r~   rN   rB   r   r   r   r	   rY   `  s    zStdExpPathPrinter.childrenN
r   r   r   r   rP   rH  r\   r   r~   rY   r   r   r   r	   r>  /  s   r>  c                   @   s@   e Zd ZdZdd Zdd Zdd ZG dd	 d	eZd
d Z	dS )StdPathPrinterzPrint a std::filesystem::pathc                 C   sP   || _ || _t| j d d }|tdd@ | _| jdkrF|| _nd | _d S )Nr?  r   Z	uintptr_t   r   )rN   rB   rg   r`   r   r   r   r   )r   rB   rN   r   r   r   r	   rP   f  s    
zStdPathPrinter.__init__c                 C   sH   t | jt| jd }|dd  dkr0dS |dd  dkrDdS d S )Nz::_TyperA  rB  rC  rD  rE  rF  )r   r   r`   r   r   rB   rG  r   r   r	   rH  p  s    zStdPathPrinter._path_typec                 C   s8   d| j d  }| jdkr0|  }|r0d||f }d| S )Nr   rI  r   rJ  zfilesystem::path %s)rN   r   rH  rK  r   r   r	   r\   x  s    
zStdPathPrinter.to_stringc                   @   s$   e Zd Zdd Zdd Zdd ZdS )zStdPathPrinter._iteratorc           	      C   s   || _ |rtd}t|d }td}|| }| }ttjdrbtd|j	 |j
}n
d|j	 }|| | }|| | _| j| | _d| _nd | _d | _d S )Nr   z::_Cmptcharalignofr   r   )rM  r   r   r`   rW   rk   r   r7   maxr   rT  r   r   ry   )	r   r   rM  Zint_typeZ	cmpt_typeZ	char_typer   Zsizeof_Implbeginr   r   r	   rP     s     


z!StdPathPrinter._iterator.__init__c                 C   s   | S r   r   r   r   r   r	   rQ     s    z!StdPathPrinter._iterator.__iter__c                 C   sd   | j | jkrt| j  }| j}| jd | _| j d | _ |d }t| j| }|sX|}d| |fS rN  )r   r   rS   rk   ry   rQ  rM  rH  rO  r   r   r	   r     s    
z!StdPathPrinter._iterator.__next__Nr}   r   r   r   r	   r~     s   r~   c                 C   s   |  | j| jS r   )r~   r   rB   r   r   r   r	   rY     s    zStdPathPrinter.childrenNrP  r   r   r   r	   rQ  c  s   
(rQ  c                   @   s8   e Zd ZdZdd ZG dd deZdd Zdd	 Zd
S )StdPairPrinterz?Print a std::pair object, with 'first' and 'second' as childrenc                 C   s
   || _ d S r   rM   rX   r   r   r	   rP     s    zStdPairPrinter.__init__c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	zStdPairPrinter._iterz?An iterator for std::pair types. Returns 'first' then 'second'.c                 C   s   || _ d| _d S )Nr   )rN   whichrO   r   r   r	   rP     s    zStdPairPrinter._iter.__init__c                 C   s   | S r   r   r   r   r   r	   rQ     s    zStdPairPrinter._iter.__iter__c                 C   s8   | j d krt| j }|dkr$d| _ nd | _ || j| fS r  )rX  rS   rN   )r   rX  r   r   r	   r     s    
zStdPairPrinter._iter.__next__NrT   r   r   r   r	   r     s   r   c                 C   s   |  | jS r   )r   rN   r   r   r   r	   rY     s    zStdPairPrinter.childrenc                 C   s   d S r   r   r   r   r   r	   r\     s    zStdPairPrinter.to_stringN)	r   r   r   r   rP   r   r   rY   r\   r   r   r   r	   rW    s
   rW  c                   @   s    e Zd ZdZdd Zdd ZdS )StdCmpCatPrinterz"Print a comparison category objectc                 C   s&   || dd d  | _|d | _d S )N:r&   r5  )rfindrB   rN   rX   r   r   r	   rP     s    zStdCmpCatPrinter.__init__c                 C   sD   | j dkr| jdkrd}nddddd}|t| j }d	| j |S )
Nstrong_orderingr   ZequalZ	unorderedZlessZ
equivalentZgreater)r   r^   r   r&   zstd::{}::{})rB   rN   r   r'   )r   r   namesr   r   r	   r\     s
    zStdCmpCatPrinter.to_stringNr   r   r   r   r	   rY    s   rY  c                   @   s0   e Zd ZdZdZdd Zedd Zdd ZdS )	StdErrorCodePrinterz/Print a std::error_code or std::error_conditionNc                 C   sT   || _ t|| _tjd krPdgt_zdd l}tjd W n tk
rN   Y nX d S )Ngenericr   system)rN   r8   rB   r^  _errno_categoriesposixrG   ImportError)r   rB   rN   rb  r   r   r	   rP     s    

zStdErrorCodePrinter.__init__c                 C   s   t d|  t d S )zDCall the virtual function that overrides std::error_category::name()Z__catz$__cat->name())r   set_convenience_variableparse_and_evalr   )catr   r   r	   _category_name  s    z"StdErrorCodePrinter._category_namec                 C   s   | j d }| | j d }t|}|dkrZddd}| jdd }||| krZ| jd	 S |dkr|tjkrztjt	| }W n   Y nX d
| j||f S )Nr5  Z_M_catr   r`  r_  )
error_codeerror_conditionr%   r^   z = { }z%s = {"%s": %s})
rN   rg  r   rB   splitr^  ra  errnoZ	errorcoder   )r   valuecategoryZstrvalZdefault_catsr   r   r   r	   r\     s    


zStdErrorCodePrinter.to_string)	r   r   r   r   ra  rP   r   rg  r\   r   r   r   r	   r^    s   
r^  c                       s$   e Zd Z fddZdd Z  ZS )	RxPrinterc                    s$   t t|   || _|| _d| _d S NT)r)  rn  rP   r   r"  enabled)r   r   r"  r,  r   r	   rP     s    zRxPrinter.__init__c                 C   s:   | j s
d S |jjtjkr,ttjdr,| }| | j	|S )Nreferenced_value)
rp  r   r   r   r   r   Valuerq  r"  r   )r   rl  r   r   r	   invoke  s    zRxPrinter.invoke)r   r   r   rP   rs  r1  r   r   r,  r	   rn    s   rn  c                       sH   e Zd Z fddZdd Zdd Zdd Zed	d
 Zdd Z	  Z
S )Printerc                    s6   t t|   || _g | _i | _d| _td| _	d S )NTz^([a-zA-Z0-9_:]+)(<.*>)?$)
r)  rt  rP   r   subprinterslookuprp  r;   compilecompiled_rx)r   r   r,  r   r	   rP     s    zPrinter.__init__c                 C   s<   | j |std| t||}| j| || j|< d S )Nz0libstdc++ programming error: "%s" does not match)rx  r<   r   rn  ru  rG   rv  )r   r   r"  printerr   r   r	   add   s
    
zPrinter.addc                 C   s:   |  || | tr6tddt |}|  || | d S )Nz^(std|__gnu_cxx)::z\g<0>%s)rz  r*   r;   r&  )r   rw   r   r"  Zvbaser   r   r	   add_version*  s    zPrinter.add_versionc                 C   s$   |  ||| |  |d || d S )Nz__cxx1998::)r{  )r   rw   r   r"  r   r   r	   add_container1  s    zPrinter.add_containerc                 C   s&   | j tjkr|  } |   } | jS r   )r   r   r   r   r   r   r   )r   r   r   r	   get_basic_type5  s    zPrinter.get_basic_typec                 C   sr   |  |j}|sd S | j|}|s(d S |d}|jjtjkrTttj	drT|
 }|| jkrn| j| |S d S )Nr&   rq  )r}  r   rx  r<   r(  r   r   r   r   rr  rq  rv  rs  )r   rN   rB   r<   basenamer   r   r	   __call__@  s    

zPrinter.__call__)r   r   r   rP   rz  r{  r|  r   r}  r  r1  r   r   r,  r	   rt    s   


rt  c                   @   s0   e Zd ZdZdd ZG dd deZdd ZdS )	TemplateTypePrinteral  
    A type printer for class templates with default template arguments.

    Recognizes specializations of class templates and prints them without
    any template arguments that use a default template argument.
    Type printers are recursively applied to the template arguments.

    e.g. replace "std::vector<T, std::allocator<T> >" with "std::vector<T>".
    c                 C   s   || _ || _d| _d S ro  )r   defargsrp  r   r   r  r   r   r	   rP   d  s    zTemplateTypePrinter.__init__c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	zTemplateTypePrinter._recognizer-The recognizer class for TemplateTypePrinter.c                 C   s   || _ || _d S r   )r   r  r  r   r   r	   rP   l  s    z(TemplateTypePrinter._recognizer.__init__c           	   	   C   s   |j dkrdS |j | js dS t|}g }d}tt|D ]}|| }| j|}|dk	r|j| }z|t	
|kr~W  dS W n( t	jk
r   |j |krY  dS Y nX d}q<|r dS || | q<|j d|j d }t|}|d d| d S )a  
            If type_obj is a specialization of self.name that uses all the
            default template arguments for the class template, then return
            a string representation of the type without default arguments.
            Otherwise, return None.
            NFTr   <r!   >)r   r9   r   rK   ranger   r  getr'   r   r   r)   rG   _recognize_subtyper   rF   r(   )	r   rH   rJ   Zdisplayed_argsZrequire_defaultedrI   ZtargZdefargr>   r   r   r	   	recognizeq  s2    


z)TemplateTypePrinter._recognizer.recognizec                 C   s   |j tjkr| | d S |j tjkrj| | }t| drR|d S d||	 d d f S |j tj
kr| | d S ttdr|j tjkr| | d S tjtj |}|r|S t|S )zxConvert a gdb.Type to a string by applying recognizers,
            or if that fails then simply converting to a string.*z[]z%s[%d]r&   &TYPE_CODE_RVALUE_REFz&&)r   r   TYPE_CODE_PTRr  r   r   r   r   endswithr  r   r   r  r  r  r  )r   rH   rE   r   r   r	   r    s&    
 z2TemplateTypePrinter._recognizer._recognize_subtypeN)r   r   r   r   rP   r  r  r   r   r   r	   _recognizeri  s   1r  c                 C   s   |  | j| jS z1Return a recognizer object for this type printer.)r  r   r  r   r   r   r	   instantiate  s    zTemplateTypePrinter.instantiateNr   r   r   r   rP   objectr  r  r   r   r   r	   r  Y  s   
Pr  c                    s~   t d| |}tj| | t d| |}tj| | trzdt  t fdd| D }t  | |}tj| | dS )a  
    Add a type printer for a class template with default template arguments.

    Args:
        name (str): The template-name of the class template.
        defargs (dict int:string) The default template arguments.

    Types in defargs can refer to the Nth template-argument using {N}
    (with zero-based indices).

    e.g. 'unordered_map' has these defargs:
    { 2: 'std::hash<{0}>',
      3: 'std::equal_to<{0}>',
      4: 'std::allocator<std::pair<const {0}, {1}> >' }

    r0   zstd::__debug::c                 3   s"   | ]\}}|| d  fV  qdS )r0   N)r+   )r"   rI   dnsr   r	   	<genexpr>  s     z0add_one_template_type_printer.<locals>.<genexpr>N)r  r   r  register_type_printerr*   dictitems)objr   r  ry  r   r  r	   add_one_template_type_printer  s    r  c                   @   s0   e Zd ZdZdd ZG dd deZdd ZdS )	FilteringTypePrintera  
    A type printer that uses typedef names for common template specializations.

    Args:
        match (str): The class template to recognize.
        name (str): The typedef-name that will be used instead.

    Checks if a specialization of the class template 'match' is the same type
    as the typedef 'name', and prints it as 'name' instead.

    e.g. if an instantiation of std::basic_istream<C, T> is the same type as
    std::istream then print it as std::istream.
    c                 C   s   || _ || _d| _d S ro  )r<   r   rp  r   r<   r   r   r   r	   rP     s    zFilteringTypePrinter.__init__c                   @   s    e Zd ZdZdd Zdd ZdS )z FilteringTypePrinter._recognizerr  c                 C   s   || _ || _d | _d S r   )r<   r   rH   r  r   r   r	   rP     s    z)FilteringTypePrinter._recognizer.__init__c                 C   sf   |j dkrdS | jdkrN|j | js*dS zt| j | _W n   Y nX | j|krbt| jS dS )z
            If type_obj starts with self.match and is the same type as
            self.name then return self.name, otherwise None.
            N)	r   rH   r9   r<   r   r   r   r   rF   )r   rH   r   r   r	   r    s    



z*FilteringTypePrinter._recognizer.recognizeN)r   r   r   r   rP   r  r   r   r   r	   r    s   r  c                 C   s   |  | j| jS r  )r  r<   r   r   r   r   r	   r    s    z FilteringTypePrinter.instantiateNr  r   r   r   r	   r    s   r  c                 C   sP   t d| d| }tj| | trLdt }t || || }tj| | d S )Nr0   )r  r   r  r  r*   )r  r<   r   ry  r  r   r   r	   add_one_type_printer  s    r  c                 C   s  t sd S dD ]H}t| d|d  t| d|d  t| dd| d  t| d|d  qdD ]T}d	D ]}t| d
| ||  qbdD ],}t| d
| ||  t| d| ||  qqZdD ]j}dD ]}t| |d || d  qdD ]>}t| |d || d  dD ]}t| || || |  qqqt| dd dD ]}t| d| q0t| dd t| dd t| dd t| dd t| dd t| dd  t| d!d" t| d!d# t| d$d% d&}dD ]}t| |d || d  qt| d'd(d)i t| d*d(d+i t| d,d(d+i t| d-d(d+i t| d.d(d+i t| d/d(d+i t| d0d1d2d3 t| d4d1d2d3 t| d5d1d+d6 t| d7d1d+d6 t| d8d9d:d2d; t| d<d9d:d2d; t| d=d9d:d+d> t| d?d9d:d+d> d S )@N)r@   r   u8u16u32basic_stringr   z__cxx11::basic_string	__cxx11::basic_string_viewZstring_view)r@   r   )	ZiosZ	streambufZistreamZostreamZiostreamZfilebufZifstreamZofstreamZfstreamZbasic_)Z	stringbufZistringstreamZostringstreamZstringstreamz__cxx11::basic_)r@   r  Zbasic_regexregex)r   sZwcZwsZmatch_resultsr<   )Z	sub_matchZregex_iteratorZregex_token_iteratorZfposZ	streampos)ZnanosecondsZmicrosecondsZmillisecondsZsecondsZminutesZhoursZdurationZlinear_congruential_engineZminstd_rand0Zminstd_randZmersenne_twister_engineZmt19937Z
mt19937_64Zsubtract_with_carry_engineZranlux24_baseZranlux48_baseZdiscard_block_engineZranlux24Zranlux48Zshuffle_order_engineZknuth_bzexperimental::fundamentals_v1::
unique_ptrr&   zstd::default_delete<{0}>dequezstd::allocator<{0}>r   r   z__cxx11::listvectorr   zstd::less<{0}>z)std::allocator<std::pair<{0} const, {1}>>)r   rR  multimapr<  )r&   r   multisetunordered_mapzstd::hash<{0}>zstd::equal_to<{0}>)r   rR     unordered_multimapunordered_set)r&   r   rR  unordered_multiset)r  r  r  )r  Zchr=   ZabiZdurr  r   r   r	   register_type_printers  s    


r  c                 C   s8   t rtj| t n| dkr t} | jt t|  dS )z4Register libstdc++ pretty-printers with objfile Obj.N)_use_gdb_ppr   printingregister_pretty_printerlibstdcxx_printerpretty_printersrG   r  )r  r   r   r	   register_libstdcxx_printersy  s    r  c                   C   s  t datddt tddt tddt tddt tddt tddt tdd	t tdd	t tdd
t	 tddt	 tddt
 tddt tddt tddt tddt tddt
 tddt tddt tddt tdt tdt tdt tdt	 tdt	 tdt
 tdt tdt tdt
 tdt tdt td t tdd!t tdd"t tdd#t tdd$t tdd%t tdd&t tdd't td(d!t td(d"t td(d#t td(d$t td(d%t td(d&t td)t td*t td+t td,t td-t td.d/t td.d0t td.d1t td2d3t td4d3t td5d3t td6d3t tdd/t tdd0t tdd1t tdd7t tdd8t tdd9t tdd:t tdd;t td<d=t tdd>t tdd?t tdd@t tddAt tddBt  tddCt  td<dDt! td<dEt" tddFt# tddGt# tdHt$ d S )INzlibstdc++-v6r0   r  rC   Zbitsetr  rh  ri  r   r   r  r  r   Zpriority_queueZqueuerf   r<  stackr  r  zstd::__debug::bitsetzstd::__debug::dequezstd::__debug::listzstd::__debug::mapzstd::__debug::multimapzstd::__debug::multisetzstd::__debug::priority_queuezstd::__debug::queuezstd::__debug::setzstd::__debug::stackzstd::__debug::unique_ptrzstd::__debug::vectorZ
shared_ptrZweak_ptrr  r  r  r  r   z
std::tr1::zstd::__debug::unordered_mapzstd::__debug::unordered_setz std::__debug::unordered_multimapz std::__debug::unordered_multisetzstd::__debug::forward_listz$std::experimental::fundamentals_v1::anyoptionalr  z#std::experimental::filesystem::v1::rL  z,std::experimental::filesystem::v1::__cxx11::zstd::filesystem::zstd::filesystem::__cxx11::ZvariantZ_Node_handleZpartial_orderingZweak_orderingr\  z__gnu_cxx::ZslistZ_List_iteratorZ_List_const_iteratorZ_Rb_tree_iteratorZ_Rb_tree_const_iteratorZ_Deque_iteratorZ_Deque_const_iteratorZ__normal_iteratorZ_Slist_iteratorZ_Fwd_list_iteratorZ_Fwd_list_const_iteratorz__gnu_debug::_Safe_iterator)%rt  r  r{  r   r|  r   r   r^  rs   r   r   rW  r   r   rh   r   rz  rU   r  r  r  r%  r2  r=  r>  rQ  r6  r9  rY  r   r   r   r   r   r   r   r   r   r   r   r	   build_libstdcxx_dictionary  sN               r  )Wr   r  r;   r  osrk  r   r  r   r   r   zipr   r   r   r  gdb.printingrc  r  	gdb.typesr   r  r    r*   r/   r6   r3   r?   r8   rF   rK   rL   rU   rb   rd   rg   rh   rl   rr   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r$  r%  r2  r6  r9  r=  r>  rQ  rW  rY  r^  rn  rt  r  r  r  r  r  r  r  r  r   r   r   r	   <module>   s   
	%!HR')#.@!,$+/ )4I )@d 4` 