o ?Og~@sdZddlZddlZddlZddlmZmZmZgdZeeBeBZ Gddde Z GdddZ d d Z Gd d d Zd dZddZGddde ZddZddZddZdS)zDebugger basicsN) CO_GENERATOR CO_COROUTINECO_ASYNC_GENERATOR)BdbQuitBdb Breakpointc@seZdZdZdS)rz Exception to give up completely.N)__name__ __module__ __qualname____doc__r r */opt/alt/python310/lib64/python3.10/bdb.pyr src@seZdZdZd^ddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd_d&d'Zd^d(d)Zd*d+Zd,d-Zd.d/Zd^d0d1Zd2d3Zd4d5Zd6d7Z  d`d9d:Zd;d<Zd=d>Z d?d@Z!dAdBZ"dCdDZ#dEdFZ$dGdHZ%dIdJZ&dKdLZ'dMdNZ(dOdPZ)dQdRZ*dadTdUZ+dbdVdWZ,dbdXdYZ-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|_|dSN)setskipbreaksfncacheframe_returning _load_breaks)selfrr r r __init__s  z Bdb.__init__cCsR|d|dddkr|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 "", generated in interactive mode, are returned unchanged. <>)rgetospathabspathnormcase)rfilenamecanonicr r r r!'s    z Bdb.canoniccCs&ddl}|d|_|dddS)z5Set values of attributes as ready to start debugging.rN) linecache checkcachebotframe _set_stopinfo)rr"r r r 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. NlineZcallreturnZ exceptionZc_callZ c_exceptionZc_returnz*bdb.Bdb.dispatch: unknown debugging event:)quitting dispatch_line dispatch_calldispatch_returndispatch_exceptiontrace_dispatchprintrepr)rframeZeventargr r r 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.rr1r r r r*js  zBdb.dispatch_linecCsd|jdur |j|_|jS||s||sdS|jr$|jjt@r$|jS| |||j r/t |jS)a Invoke 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.r3break_anywhere stopframef_codeco_flagsGENERATOR_AND_COROUTINE_FLAGS user_callr)rrr1r2r r r r+vs   zBdb.dispatch_callcCs||s ||jkr>|jr|jjt@r|jSz||_|||Wd|_nd|_w|j r.t |j|ur>|j dkr>| 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>r r r 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. rN) r3r:r;r< StopIterationuser_exceptionr)rr9 GeneratorExitr.r>r r r r-s        zBdb.dispatch_exceptioncCs.|durdS|jD] }t||rdSq dS)z4Return True if module_name matches any skip pattern.NFT)rfnmatch)rZ module_namepatternr r r is_skipped_modules  zBdb.is_skipped_modulecCsN|jr||jdrdS||jur |jdkrdS|j|jkS|js%dSdS)z>Return True if frame is below the starting frame in the stack.rFrT)rrH f_globalsrr9rAf_linenor6r r r r3s   z Bdb.stop_herecCs||jj}||jvrdS|j}||j|vr%|jj}||j|vr%dSt|||\}}|rB|j|_|r@|j r@| t |jdSdS)zReturn 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_filenamerrJco_firstlineno effectivenumberZ currentbp temporarydo_clearstr)rr1r linenobpflagr r r r4s  zBdb.break_herecCstd)zlRemove temporary breakpoint. Must implement in derived classes or get NotImplementedError. z)subclass of bdb must implement do_clear())NotImplementedError)rr2r r r rPsz Bdb.do_clearcCs||jj|jvS)zEReturn True if there is any breakpoint for frame's filename. )r!r:rKrr6r r r r8szBdb.break_anywherecCdS)z&Called if we might stop in a function.Nr )rr1Z argument_listr r r r=z Bdb.user_callcCrV)z'Called when we stop or break at a line.Nr r6r r r r5rWz Bdb.user_linecCrV)z&Called when a return trap is set here.Nr )rr1Z return_valuer r r r@ rWzBdb.user_returncCrV)z$Called when we stop on an exception.Nr )rr1exc_infor r r rDrWzBdb.user_exceptionrcCs||_||_d|_||_dS)zSet 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?rAr r r 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%)rr1rRr r r set_until$s z Bdb.set_untilcCs0|jr|jj}|r|js|j|_|dddS)zStop after one line of code.N)rr7f_tracer.r%)rZ caller_framer r r set_step,s  z Bdb.set_stepcCs||ddS)z2Stop on the next line in or below the given frame.N)r%r6r r r set_next8sz Bdb.set_nextcCs0|jjt@r||dddS||j|dS)z)Stop when returning from the given frame.Nr)r:r;r<r%r7r6r r r set_return<s zBdb.set_returncCsN|dur tj}||r|j|_||_|j}|s|t|jdS)znStart debugging from frame. If frame is not specified, debugging starts from caller's frame. N) sys _getframer7r&r.rZr$r[settracer6r r r set_traceCs z Bdb.set_tracecCsd||jdd|js*tdtj}|r,||jur0|`|j}|r.||jusdSdSdSdSdS)zStop only at breakpoints or when finished. If there are no breakpoints, set the system trace function to None. Nr)r%r$rr^r`r_r7rZr6r r r set_continueRs   zBdb.set_continuecCs"|j|_d|_d|_tddS)zuSet quitting attribute to True. Raises BdbQuit exception in the next call to a dispatch_*() method. NT)r$r9r?r)r^r`rr r r set_quitasz Bdb.set_quitcCs(|j|g}||vr||dSdS)z/Add breakpoint to breaks, if not already there.N)r setdefaultappend)rr rRZ bp_linenosr r r _add_to_breaksrszBdb._add_to_breaksFc CsN||}ddl}|||}|sd||fS|||t|||||}dS)zSet 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 rRrOcondfuncnamer"r'rSr r r set_breakxs    z Bdb.set_breakcCs$tjD] \}}|||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)rbplistkeysrgrr rRr r r rszBdb._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)rrlrremovernr r r _prune_breakss   zBdb._prune_breakscCsj||}||jvrd|S||j|vrd||fStj||fddD]}|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!rrrldeleteMerp)rr rRrSr r r clear_breaks     zBdb.clear_breakc CsXz||}Wnty}z t|WYd}~Sd}~ww|||j|jdS)zxDelete a breakpoint by its index in Breakpoint.bpbynumber. If arg is invalid, return an error message. N)get_bpbynumber ValueErrorrQrrrpfiler')rr2rSerrr r r clear_bpbynumberszBdb.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'ZblistrSr r r clear_all_file_breakss   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)rrSr r r clear_all_breakss zBdb.clear_all_breakscCsz|stdzt|}Wntytd|dwztj|}Wnty0td|dw|dur;td||S)zReturn 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)ruintrrz IndexError)rr2rNrSr r r rts    zBdb.get_bpbynumbercCs"||}||jvo||j|vS)z9Return True if there is a breakpoint for filename:lineno.r!rrnr r r get_breaks   z Bdb.get_breakcCs4||}||jvr||j|vrtj||fpgS)znReturn all breakpoints for filename:lineno. If no breakpoints are set, return an empty list. )r!rrrlrnr r r get_breakss    zBdb.get_breakscCs"||}||jvr|j|SgS)zrReturn all lines with breakpoints for filename. If no breakpoints are set, return an empty list. r~)rr r r r get_file_breakss   zBdb.get_file_breakscCs|jS)z$Return all breakpoints that are set.)rrcr r r get_all_breaks szBdb.get_all_breakscCsg}|r |j|ur |j}|dur%|||jf||jurn|j}|dus|tdt|d}|durF||j|j f|j}|dus6|durStdt|d}||fS)zReturn 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_frametb_nextrfrJr$r7reversemaxlen tb_lineno)rftstackir r r get_stacks$ z Bdb.get_stack: c Csddl}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 '', the input arguments, the return value, and the line of code (if it exists). rNz%s(%r)zz()Z __return__z->) r"reprlibr!r:rKco_namef_localsr0rhrIstrip) rZ frame_linenoZlprefixr"rr1rRr sZrvr'r r r format_stack_entry's"    zBdb.format_stack_entryc Cs|dur ddl}|j}|dur|}|t|tr t|dd}t|jz(zt |||Wn t y8Yn wWd|_ tddSWd|_ tddSd|_ tdw)zDebug a statement executed via the exec() function. globals defaults to __main__.dict; locals defaults to globals. NrzexecT) __main____dict__r& isinstancerQcompiler^r`r.rrr))rcmdglobalslocalsrr r r runGs,     zBdb.runc Cs|dur ddl}|j}|dur|}|t|jz%zt|||WWd|_tdSty5YnwWd|_tddSd|_tdw)zDebug an expression executed via the eval() function. globals defaults to __main__.dict; locals defaults to globals. NrT) rrr&r^r`r.evalr)r)rexprrrrr r r runeval]s&    z Bdb.runevalcCs||||dS)z.For backwards-compatibility. Defers to run().N)r)rrrrr r r runctxqsz Bdb.runctxc Os~|t|jd}z)z ||i|}Wn tyYn wWd|_td|SWd|_td|Sd|_tdw)zWDebug a single function call. Return the result of the function call. NT)r&r^r`r.rr))rfuncargskwdsresr r r runcallxs$     z Bdb.runcallr)rFNN)rNN)0rr r r rr!r&r.r*r+r,r-rHr3r4rPr8r=r5r@rDr%rYr[r\r]rarbrdrgrkrrprsrxryr{rtrrrrrrrrrrr r r r rs` +                rcCstdS)zs* }z 5