????
Your IP : 3.141.244.160
o
�?Og�~�@s�dZddlZddlZddlZddlmZmZmZgd�ZeeBeBZ Gdd�de
�ZGdd�d�Zd d
�Z
Gdd�d�Zd
d�Zdd�ZGdd�de�Zdd�Zdd�Zdd�ZdS)zDebugger basics�N)�CO_GENERATOR�CO_COROUTINE�CO_ASYNC_GENERATOR)�BdbQuit�Bdb�
Breakpointc@seZdZdZdS)rz Exception to give up completely.N)�__name__�
__module__�__qualname__�__doc__�rr�*/opt/alt/python310/lib64/python3.10/bdb.pyr
src@s�eZdZdZd^dd�Zdd�Zdd�Zd d
�Zdd�Zd
d�Z dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd_d&d'�Zd^d(d)�Zd*d+�Zd,d-�Zd.d/�Zd^d0d1�Zd2d3�Zd4d5�Zd6d7�Z d`d9d:�Zd;d<�Zd=d>�Z d?d@�Z!dAdB�Z"dCdD�Z#dEdF�Z$dGdH�Z%dIdJ�Z&dKdL�Z'dMdN�Z(dOdP�Z)dQdR�Z*dadTdU�Z+dbdVdW�Z,dbdXdY�Z-dZd[�Z.d\d]�Z/dS)craGeneric Python debugger base class.
This class takes care of details of the trace facility;
a derived class should implement user interaction.
The standard debugger class (pdb.Pdb) is an example.
The optional skip argument must be an iterable of glob-style
module name patterns. The debugger will not step into frames
that originate in a module that matches one of these patterns.
Whether a frame is considered to originate in a certain module
is determined by the __name__ in the frame globals.
NcCs0|rt|�nd|_i|_i|_d|_|��dS�N)�set�skip�breaks�fncache�frame_returning�_load_breaks)�selfrrrr
�__init__s
zBdb.__init__cCsR|d|dd�dkr|S|j�|�}|s'tj�|�}tj�|�}||j|<|S)a%Return canonical form of filename.
For real filenames, the canonical form is a case-normalized (on
case insensitive filesystems) absolute path. 'Filenames' with
angle brackets, such as "<stdin>", generated in interactive
mode, are returned unchanged.
�<�����>)r�get�os�path�abspath�normcase)r�filename�canonicrrr
r!'s
zBdb.canoniccCs&ddl}|��d|_|�dd�dS)z5Set values of attributes as ready to start debugging.rN)� linecache�
checkcache�botframe�
_set_stopinfo)rr"rrr
�reset8sz Bdb.resetcCs�|jrdS|dkr|�|�S|dkr|�||�S|dkr"|�||�S|dkr,|�||�S|dkr3|jS|dkr:|jS|dkrA|jStd t|��|jS)
aODispatch a trace function for debugged frames based on the event.
This function is installed as the trace function for debugged
frames. Its return value is the new trace function, which is
usually itself. The default implementation decides how to
dispatch a frame, depending on the type of event (passed in as a
string) that is about to be executed.
The event can be one of the following:
line: A new line of code is going to be executed.
call: A function is about to be called or another code block
is entered.
return: A function or other code block is about to return.
exception: An exception has occurred.
c_call: A C function is about to be called.
c_return: A C function has returned.
c_exception: A C function has raised an exception.
For the Python events, specialized functions (see the dispatch_*()
methods) are called. For the C events, no action is taken.
The arg parameter depends on the previous event.
N�lineZcall�returnZ exceptionZc_callZc_exceptionZc_returnz*bdb.Bdb.dispatch: unknown debugging event:)�quitting�
dispatch_line�
dispatch_call�dispatch_return�dispatch_exception�trace_dispatch�print�repr)r�frameZevent�argrrr
r.?s$
zBdb.trace_dispatchcCs.|�|�s
|�|�r|�|�|jrt�|jS)a Invoke user function and return trace function for line event.
If the debugger stops on the current line, invoke
self.user_line(). Raise BdbQuit if self.quitting is set.
Return self.trace_dispatch to continue tracing in this scope.
)� stop_here�
break_here� user_liner)rr.�rr1rrr
r*js
zBdb.dispatch_linecCsd|jdur|j|_|jS|�|�s|�|�sdS|jr$|jjt@r$|jS|� ||�|j
r/t�|jS)aInvoke user function and return trace function for call event.
If the debugger stops on this function call, invoke
self.user_call(). Raise BdbQuit if self.quitting is set.
Return self.trace_dispatch to continue tracing in this scope.
N)r$�f_backr.r3�break_anywhere� stopframe�f_code�co_flags�GENERATOR_AND_COROUTINE_FLAGS� user_callr)r�rr1r2rrr
r+vs
zBdb.dispatch_callcCs�|�|�s
||jkr>|jr|jjt@r|jSz||_|�||�Wd|_nd|_w|j r.t
�|j|ur>|jdkr>|�dd�|jS)aInvoke user function and return trace function for return event.
If the debugger stops on this function return, invoke
self.user_return(). Raise BdbQuit if self.quitting is set.
Return self.trace_dispatch to continue tracing in this scope.
Nr)
r3�returnframer9r:r;r<r.r�user_returnr)r�
stoplinenor%r>rrr
r,�s
zBdb.dispatch_returncCs�|�|�r%|jjt@r|dtur|ddus"|�||�|jr"t�|j
S|jrG||jurG|jjjt@rG|dtt fvrG|�||�|jrGt�|j
S)aInvoke user function and return trace function for exception event.
If the debugger stops on this exception, invoke
self.user_exception(). Raise BdbQuit if self.quitting is set.
Return self.trace_dispatch to continue tracing in this scope.
r�N)r3r:r;r<�
StopIteration�user_exceptionr)rr9�
GeneratorExitr.r>rrr
r-�s
��
zBdb.dispatch_exceptioncCs.|durdS|jD]}t�||�rdSq dS)z4Return True if module_name matches any skip pattern.NFT)r�fnmatch)rZmodule_name�patternrrr
�is_skipped_module�s
�zBdb.is_skipped_modulecCsN|jr|�|j�d��rdS||jur |jdkrdS|j|jkS|js%dSdS)z>Return True if frame is below the starting frame in the stack.rFrT)rrH� f_globalsrr9rA�f_linenor6rrr
r3�s�
z
Bdb.stop_herecCs�|�|jj�}||jvrdS|j}||j|vr%|jj}||j|vr%dSt|||�\}}|rB|j|_|r@|j r@|�
t|j��dSdS)z�Return True if there is an effective breakpoint for this line.
Check for line or function breakpoint and if in effect.
Delete temporary breakpoints if effective() says to.
FT)r!r:�co_filenamerrJ�co_firstlineno� effective�numberZ currentbp� temporary�do_clear�str)rr1r �lineno�bp�flagrrr
r4�s
zBdb.break_herecCstd��)zlRemove temporary breakpoint.
Must implement in derived classes or get NotImplementedError.
z)subclass of bdb must implement do_clear())�NotImplementedError)rr2rrr
rP�szBdb.do_clearcCs|�|jj�|jvS)zEReturn True if there is any breakpoint for frame's filename.
)r!r:rKrr6rrr
r8�szBdb.break_anywherecC�dS)z&Called if we might stop in a function.Nr)rr1Z
argument_listrrr
r=�z
Bdb.user_callcCrV)z'Called when we stop or break at a line.Nrr6rrr
r5rWz
Bdb.user_linecCrV)z&Called when a return trap is set here.Nr)rr1Zreturn_valuerrr
r@rWzBdb.user_returncCrV)z$Called when we stop on an exception.Nr)rr1�exc_inforrr
rDrWzBdb.user_exceptionrcCs||_||_d|_||_dS)z�Set the attributes for stopping.
If stoplineno is greater than or equal to 0, then stop at line
greater than or equal to the stopline. If stoplineno is -1, then
don't stop at all.
FN)r9r?r)rA)rr9r?rArrr
r%s
zBdb._set_stopinfocCs$|dur |jd}|�|||�dS)zxStop when the line with the lineno greater than the current one is
reached or when returning from current frame.Nr)rJr%)rr1rRrrr
� set_until$s
z
Bdb.set_untilcCs0|jr|jj}|r|js|j|_|�dd�dS)zStop after one line of code.N)rr7�f_tracer.r%)rZcaller_framerrr
�set_step,s
zBdb.set_stepcCs|�|d�dS)z2Stop on the next line in or below the given frame.N)r%r6rrr
�set_next8szBdb.set_nextcCs0|jjt@r|�|dd�dS|�|j|�dS)z)Stop when returning from the given frame.Nr)r:r;r<r%r7r6rrr
�
set_return<szBdb.set_returncCsN|dur t��j}|��|r|j|_||_|j}|s|��t�|j�dS)znStart debugging from frame.
If frame is not specified, debugging starts from caller's frame.
N) �sys� _getframer7r&r.rZr$r[�settracer6rrr
� set_traceCs
�z
Bdb.set_tracecCsd|�|jdd�|js*t�d�t��j}|r,||jur0|`|j}|r.||jusdSdSdSdSdS)z�Stop only at breakpoints or when finished.
If there are no breakpoints, set the system trace function to None.
Nr)r%r$rr^r`r_r7rZr6rrr
�set_continueRs
��zBdb.set_continuecCs"|j|_d|_d|_t�d�dS)zuSet quitting attribute to True.
Raises BdbQuit exception in the next call to a dispatch_*() method.
NT)r$r9r?r)r^r`�rrrr
�set_quitaszBdb.set_quitcCs(|j�|g�}||vr|�|�dSdS)z/Add breakpoint to breaks, if not already there.N)r�
setdefault�append)rr rRZ
bp_linenosrrr
�_add_to_breaksrs�zBdb._add_to_breaksFc CsN|�|�}ddl}|�||�}|sd||fS|�||�t|||||�}dS)z�Set a new breakpoint for filename:lineno.
If lineno doesn't exist for the filename, return an error message.
The filename should be in canonical form.
rNzLine %s:%d does not exist)r!r"�getlinergr) rr rRrO�cond�funcnamer"r'rSrrr
� set_breakxs
z
Bdb.set_breakcCs$tj��D]
\}}|�||�qdS)aOApply all breakpoints (set in other instances) to this one.
Populates this instance's breaks list from the Breakpoint class's
list, which can have breakpoints set by another Bdb instance. This
is necessary for interactive sessions to keep the breakpoints
active across multiple calls to run().
N)r�bplist�keysrg�rr rRrrr
r�s�zBdb._load_breakscCs8||ftjvr|j|�|�|j|s|j|=dSdS)aPrune breakpoints for filename:lineno.
A list of breakpoints is maintained in the Bdb instance and in
the Breakpoint class. If a breakpoint in the Bdb instance no
longer exists in the Breakpoint class, then it's removed from the
Bdb instance.
N)rrlr�removernrrr
�
_prune_breaks�s
�zBdb._prune_breakscCsj|�|�}||jvrd|S||j|vrd||fStj||fdd�D]}|��q&|�||�dS)znDelete breakpoints for filename:lineno.
If no breakpoints were set, return an error message.
�There are no breakpoints in %szThere is no breakpoint at %s:%dN)r!rrrl�deleteMerp)rr rRrSrrr
�clear_break�s
zBdb.clear_breakc
CsXz|�|�}Wnty}z
t|�WYd}~Sd}~ww|��|�|j|j�dS)zxDelete a breakpoint by its index in Breakpoint.bpbynumber.
If arg is invalid, return an error message.
N)�get_bpbynumber�
ValueErrorrQrrrp�filer')rr2rS�errrrr
�clear_bpbynumber�s��zBdb.clear_bpbynumbercCsX|�|�}||jvrd|S|j|D]}tj||f}|D]}|��qq|j|=dS)z`Delete all breakpoints in filename.
If none were set, return an error message.
rqN)r!rrrlrr)rr r'ZblistrSrrr
�clear_all_file_breaks�s
�zBdb.clear_all_file_breakscCs,|jsdStjD]}|r|��qi|_dS)z]Delete all existing breakpoints.
If none were set, return an error message.
zThere are no breakpointsN)rr�
bpbynumberrr)rrSrrr
�clear_all_breaks�s
�zBdb.clear_all_breakscCsz|std��zt|�}Wntytd|�d�wztj|}Wnty0td|�d�w|dur;td|��|S)z�Return a breakpoint by its index in Breakpoint.bybpnumber.
For invalid arg values or if the breakpoint doesn't exist,
raise a ValueError.
zBreakpoint number expectedz Non-numeric breakpoint number %sNz!Breakpoint number %d out of rangezBreakpoint %d already deleted)ru�intrrz�
IndexError)rr2rNrSrrr
rt�s��zBdb.get_bpbynumbercCs"|�|�}||jvo||j|vS)z9Return True if there is a breakpoint for filename:lineno.�r!rrnrrr
� get_break�s
�z
Bdb.get_breakcCs4|�|�}||jvr||j|vrtj||fpgS)znReturn all breakpoints for filename:lineno.
If no breakpoints are set, return an empty list.
)r!rrrlrnrrr
�
get_breaks�s
���zBdb.get_breakscCs"|�|�}||jvr|j|SgS)zrReturn all lines with breakpoints for filename.
If no breakpoints are set, return an empty list.
r~)rr rrr
�get_file_breaks�s
zBdb.get_file_breakscCs|jS)z$Return all breakpoints that are set.)rrcrrr
�get_all_breaks szBdb.get_all_breakscCs�g}|r|j|ur|j}|dur%|�||jf�||jurn|j}|dus|��tdt|�d�}|durF|�|j|j f�|j}|dus6|durStdt|�d�}||fS)z�Return a list of (frame, lineno) in a stack trace and a size.
List starts with original calling frame, if there is one.
Size may be number of frames above or below f.
Nrr)
�tb_frame�tb_nextrfrJr$r7�reverse�max�len� tb_lineno)r�f�t�stack�irrr
� get_stacks$
��z
Bdb.get_stack�: cCs�ddl}ddl}|\}}|�|jj�}d||f}|jjr$||jj7}n|d7}|d7}d|jvrA|jd} |d7}||�| �7}|durW|�|||j �}
|
rW|||
�
�7}|S)a:Return a string with information about a stack entry.
The stack entry frame_lineno is a (frame, lineno) tuple. The
return string contains the canonical filename, the function name
or '<lambda>', the input arguments, the return value, and the
line of code (if it exists).
rNz%s(%r)z<lambda>z()Z
__return__z->)r"�reprlibr!r:rK�co_name�f_localsr0rhrI�strip)rZframe_linenoZlprefixr"r�r1rRr �sZrvr'rrr
�format_stack_entry's"
zBdb.format_stack_entryc Cs�|durddl}|j}|dur|}|��t|t�r t|dd�}t�|j�z(zt |||�Wn t
y8YnwWd|_t�d�dSWd|_t�d�dSd|_t�d�w)z�Debug a statement executed via the exec() function.
globals defaults to __main__.dict; locals defaults to globals.
Nrz<string>�execT)�__main__�__dict__r&�
isinstancerQ�compiler^r`r.r�rr))r�cmd�globals�localsr�rrr
�runGs,
����zBdb.runc Cs�|durddl}|j}|dur|}|��t�|j�z%zt|||�WWd|_t�d�Sty5YnwWd|_t�d�dSd|_t�d�w)z�Debug an expression executed via the eval() function.
globals defaults to __main__.dict; locals defaults to globals.
NrT) r�r�r&r^r`r.�evalr)r)r�exprr�r�r�rrr
�runeval]s&���zBdb.runevalcCs|�|||�dS)z.For backwards-compatibility. Defers to run().N)r�)rr�r�r�rrr
�runctxqsz
Bdb.runctxc Os~|��t�|j�d}z)z ||i|��}Wn tyYnwWd|_t�d�|SWd|_t�d�|Sd|_t�d�w)zWDebug a single function call.
Return the result of the function call.
NT)r&r^r`r.rr))r�func�args�kwds�resrrr
�runcallxs$��
�
�zBdb.runcallr)r�FNN)r��NN)0rr r
rrr!r&r.r*r+r,r-rHr3r4rPr8r=r5r@rDr%rYr[r\r]rarbrdrgrkrrprsrxryr{rtrr�r�r�r�r�r�r�r�r�rrrr
rs`
+
�
rcCst���dS)z<Start debugging with a Bdb instance from the caller's frame.N)rrarrrr
ra�srac@sfeZdZdZdZiZdgZddd�Zedd��Z d d
�Z
dd�Zd
d�Zddd�Z
dd�Zdd�ZdS)ra�Breakpoint class.
Implements temporary breakpoints, ignore counts, disabling and
(re)-enabling, and conditionals.
Breakpoints are indexed by number through bpbynumber and by
the (file, line) tuple using bplist. The former points to a
single instance of class Breakpoint. The latter points to a
list of such instances since there may be more than one
breakpoint per line.
When creating a breakpoint, its associated filename should be
in canonical form. If funcname is defined, a breakpoint hit will be
counted when the first line of that function is executed. A
conditional breakpoint always counts a hit.
rNFcCs�||_d|_||_||_||_||_d|_d|_d|_t j
|_t j
d7_
|j�
|�||f|jvr?|j||f�
|�dS|g|j||f<dS)NTrr)rj�func_first_executable_linervr'rOri�enabled�ignore�hitsr�nextrNrzrfrl)rrvr'rOrirjrrr
r�szBreakpoint.__init__cCsdt_it_dgt_dS)Nr)rr�rlrzrrrr
�clearBreakpoints�szBreakpoint.clearBreakpointscCsB|j|jf}d|j|j<|j|�|�|j|s|j|=dSdS)z�Delete the breakpoint from the list associated to a file:line.
If it is the last breakpoint in that position, it also deletes
the entry for the file:line.
N)rvr'rzrNrlro)r�indexrrr
rr�s
�zBreakpoint.deleteMecC�
d|_dS)zMark the breakpoint as enabled.TN�r�rcrrr
�enable��
zBreakpoint.enablecCr�)z Mark the breakpoint as disabled.FNr�rcrrr
�disable�r�zBreakpoint.disablecCs"|durtj}t|��|d�dS)z�Print the output of bpformat().
The optional out argument directs where the output is sent
and defaults to standard output.
N)rv)r^�stdoutr/�bpformat)r�outrrr
�bpprint�szBreakpoint.bpprintcCs�|jrd}nd}|jr|d}n|d}d|j||j|jf}|jr*|d|jf7}|jr5|d|jf7}|jrK|jdkr@d }nd
}|d|j|f7}|S)z�Return a string with information about the breakpoint.
The information includes the breakpoint number, temporary
status, file:line position, break condition, number of times to
ignore, and number of times hit.
zdel zkeep zyes zno z%-4dbreakpoint %s at %s:%dz
stop only if %sz
ignore next %d hitsrr��z"
breakpoint already hit %d time%s)rOr�rNrvr'rir�r�)rZdispZretZssrrr
r��s&
�
zBreakpoint.bpformatcCsd|j|j|jfS)z1Return a condensed description of the breakpoint.zbreakpoint %s at %s:%s)rNrvr'rcrrr
�__str__szBreakpoint.__str__r�r)rr r
rr�rlrzr�staticmethodr�rrr�r�r�r�r�rrrr
r�s
rcCsN|js
|j|jkrdSdS|jj|jkrdS|js|j|_|j|jkr%dSdS)aVReturn True if break should happen here.
Whether a break should happen depends on the way that b (the breakpoint)
was set. If it was set via line number, check if b.line is the same as
the one in the frame. If it was set via function name, check if this is
the right function and if it is on the first executable line.
FT)rjr'rJr:r�r�)�br1rrr
�
checkfuncname sr�cCs�tj||f}|D]U}|jsq t||�sq |jd7_|js2|jdkr,|jd8_q |dfSz!t|j|j|j �}|rR|jdkrK|jd8_n|dfWSWq |dfYSdS)a=Return (active breakpoint, delete temporary flag) or (None, None) as
breakpoint to act upon.
The "active breakpoint" is the first entry in bplist[line, file] (which
must exist) that is enabled, for which checkfuncname is True, and that
has neither a False condition nor a positive ignore count. The flag,
meaning that a temporary breakpoint should be deleted, is False only
when the condiion cannot be evaluated (in which case, ignore count is
ignored).
If no such entry exists, then (None, None) is returned.
rrTFr�)
rrlr�r�r�rir�r�rIr�)rvr'r1Z possiblesr��valrrr
rM)s,
�rMc@s,eZdZdd�Zdd�Zdd�Zdd�Zd S)
�TdbcCs |jj}|sd}td||�dS)N�???z+++ call)r:r�r/)rr1r��namerrr
r=_sz
Tdb.user_callcCsTddl}|jj}|sd}|�|jj�}|�||j|j�}td||j|d|� ��dS)Nrr�z+++�:)
r"r:r�r!rKrhrJrIr/r�)rr1r"r��fnr'rrr
r5csz
Tdb.user_linecCstd|�dS)Nz
+++ return�r/)rr1Zretvalrrr
r@jszTdb.user_returncCstd|�|��dS)Nz
+++ exception)r/rb)rr1Z exc_stuffrrr
rDls
zTdb.user_exceptionN)rr r
r=r5r@rDrrrr
r�^s
r�cCs&td|d�t|d�}td|�dS)Nzfoo(�)�
zbar returned)r/�bar)�n�xrrr
�foopsr�cCstd|d�|dS)Nzbar(r�rBr�)�arrr
r�usr�cCst�}|�d�dS)Nzimport bdb; bdb.foo(10))r�r�)r�rrr
�testysr�)rrFr^r�inspectrrr�__all__r<� Exceptionrrrarr�rMr�r�r�r�rrrr
�<module>s*}z 5