Current File : //usr/share/gdb/python/gdb/command/pretty_printers.pyc
�
�� Rc@s�dZddlZddlZddlZd�Zd�Zdejfd��YZd�Zd�Z	d	d
�Z
d�Zd�Zd
�Z
dejfd��YZdejfd��YZd�Ze�dS(s.GDB commands for working with pretty-printers.i����Nc
Csvtj|�}t|�}d}d}d}|dkrHtd��n|dkra|d}n|dkr�|djdd�}|d}t|�dkr�|d}q�nytj|�}Wn!tk
r�td|��nXytj|�}Wn!tk
rtd	|��nX|dk	rcytj|�}	Wqitk
r_td
|��qiXnd}	|||	fS(s�Internal utility to parse a pretty-printer command argv.

    Arguments:
        arg: The arguments to the command.  The format is:
             [object-regexp [name-regexp]].
             Individual printers in a collection are named as
             printer-name;subprinter-name.

    Returns:
        The result is a 3-tuple of compiled regular expressions, except that
        the resulting compiled subprinter regexp is None if not provided.

    Raises:
        SyntaxError: an error processing ARG
    tistoo many argumentsiiit;sinvalid object regexp: %ssinvalid name regexp: %ssinvalid subname regexp: %sN(tgdbtstring_to_argvtlentNonetSyntaxErrortsplittretcompile(
targtargvtargct
object_regexptname_regexptsubname_regexptname_subnamet	object_retname_ret
subname_re((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytparse_printer_regexpss:




cCst|d�r|jStSdS(s>Internal utility to see if printer (or subprinter) is enabled.tenabledN(thasattrRtTrue(tprinter((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytprinter_enabled_pLstInfoPrettyPrintercBsPeZdZd�Zed��Zed��Zd�Zd�Zd�Z	RS(s�GDB command to list all registered pretty-printers.

    Usage: info pretty-printer [object-regexp [name-regexp]]

    OBJECT-REGEXP is a regular expression matching the objects to list.
    Objects are "global", the program space's file, and the objfiles within
    that program space.

    NAME-REGEXP matches the name of the pretty-printer.
    Individual printers in a collection are named as
    printer-name;subprinter-name.
    cCs tt|�jdtj�dS(Nsinfo pretty-printer(tsuperRt__init__RtCOMMAND_DATA(tself((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyRbscCst|�rdSdSdS(s9Return "" if PRINTER is enabled, otherwise " [disabled]".Rs [disabled]N(R(R((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytenabled_stringfscCs0t|d�r|jSt|d�r,|jSdS(sReturn the printer's name.tnamet__name__tunknown(RR R!(R((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytprinter_namens
c
Cs�ttj|�d|j�}x�|D]�}|j|�}|j|�}|j|�r%d||fGHt|d�r�|jdk	r�ttj|j�d|j�}xH|D]=}	|s�|j|	j�r�d|	j|j|	�fGHq�q�Wq�q%q%WdS(s Print a list of pretty-printers.tkeys  %s%stsubprinterss    %s%sN(	tsortedtcopyR#RtmatchRR%RR (
Rtpretty_printersRRtsorted_pretty_printersRR Rtsorted_subprinterst
subprinter((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytlist_pretty_printers{s"

cCs4|r0|j|�r0|GH|j|||�ndS(s$Subroutine of invoke to simplify it.N(R(R-(Rttitletprinter_listtobj_name_to_matchRRR((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytinvoke1�scCs�t|�\}}}|jdtjd|||�tj�}|jd|j|jd|||�x=tj�D]/}|jd|j|j|j|||�qsWdS(s&GDB calls this to perform the command.sglobal pretty-printers:tglobalsprogspace %s pretty-printers:t	progspaces  objfile %s pretty-printers:N(RR1RR)tcurrent_progspacetfilenametobjfiles(RR
tfrom_ttyRRRtcptobjfile((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytinvoke�s	
(
R!t
__module__t__doc__RtstaticmethodRR#R-R1R:(((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyRTs	
		cCs�d}d}x�|D]�}t|d�r�|jdk	r�t|�rsx-|jD]}t|�rM|d7}qMqMWn|t|j�7}qt|�r�|d7}n|d7}qW||fS(s9Return a 2-tuple of number of enabled and total printers.iR%iN(RR%RRR(R)RttotalRR,((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytcount_enabled_printers�s

cCs�d}d}ttj�\}}||7}||7}ttj�j�\}}||7}||7}x=tj�D]/}t|j�\}}||7}||7}qqW||fS(skReturn a 2-tuble of the enabled state and total number of all printers.
    This includes subprinters.
    i(R?RR)R4R6(t
enabled_countttotal_countt	t_enabledtt_totalR9((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytcount_all_enabled_printers�s




tscCs"|dkrd||fS|SdS(s!Return TEXT pluralized if N != 1.is%s%sN((ttexttntsuffix((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyt	pluralize�scCs"t�\}}d||fGHdS(sZPrint the number of printers enabled/disabled.
    We count subprinters individually.
    s%d of %d printers enabledN(RD(R@RA((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyt#show_pretty_printer_enabled_summary�sc	Cscd}xV|D]N}t|d�r4|j|j�sUt|d�r
|j|j�r
t|d�r'|jdk	r'|s�t|�|kr�x-|jD]}t|�r�|d7}q�q�Wn||_qXx�|jD]O}|j|j�r�t|�rt|�|kr|d7}n||_q�q�Wq[|s[t|�|krL|d7}n||_q[q
q
W|S(s�Worker for enabling/disabling pretty-printers.

    Arguments:
        pretty_printers: list of pretty-printers
        name_re: regular-expression object to select printers
        subname_re: regular expression object to select subprinters or None
                    if all are affected
        flag: True for Enable, False for Disable

    Returns:
        The number of printers affected.
        This is just for informational purposes for the user.
    iR R!R%iN(RR(R R!R%RRR(R)RRtflagR>RR,((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytdo_enable_pretty_printer_1�s.
!!

c	Cst|�\}}}d}|jd�rI|ttj|||�7}ntj�}|jd�r�|t|j|||�7}nxEtj�D]7}|j|j�r�|t|j|||�7}q�q�W|r�d}nd}d|td|�|fGHt	�dS(	s7Internal worker for enabling/disabling pretty-printers.iR2R3Rtdisableds%d %s %sRN(
RR(RLRR)R4R6R5RIRJ(	R
RKRRRR>R8R9tstate((s4/usr/share/gdb/python/gdb/command/pretty_printers.pytdo_enable_pretty_printers$	tEnablePrettyPrintercBs eZdZd�Zd�ZRS(s�GDB command to enable the specified pretty-printer.

    Usage: enable pretty-printer [object-regexp [name-regexp]]

    OBJECT-REGEXP is a regular expression matching the objects to examine.
    Objects are "global", the program space's file, and the objfiles within
    that program space.

    NAME-REGEXP matches the name of the pretty-printer.
    Individual printers in a collection are named as
    printer-name;subprinter-name.
    cCs tt|�jdtj�dS(Nsenable pretty-printer(RRPRRR(R((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyRJscCst|t�dS(s&GDB calls this to perform the command.N(ROR(RR
R7((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyR:Ns(R!R;R<RR:(((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyRP<s	tDisablePrettyPrintercBs eZdZd�Zd�ZRS(s�GDB command to disable the specified pretty-printer.

    Usage: disable pretty-printer [object-regexp [name-regexp]]

    OBJECT-REGEXP is a regular expression matching the objects to examine.
    Objects are "global", the program space's file, and the objfiles within
    that program space.

    NAME-REGEXP matches the name of the pretty-printer.
    Individual printers in a collection are named as
    printer-name;subprinter-name.
    cCs tt|�jdtj�dS(Nsdisable pretty-printer(RRQRRR(R((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyRascCst|t�dS(s&GDB calls this to perform the command.N(ROtFalse(RR
R7((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyR:es(R!R;R<RR:(((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyRQSs	cCst�t�t�dS(sDCall from a top level script to install the pretty-printer commands.N(RRPRQ(((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyt register_pretty_printer_commandsjs(R<R'RRRRtCommandRR?RDRIRJRLRORPRQRS(((s4/usr/share/gdb/python/gdb/command/pretty_printers.pyt<module>s 	4	S				:	%