ל5dZddlZddlZddlZddlmZddlmZmZm Z gdZ eeze zZ Gdde Z Gdd Zd ZGd d Zd ZdZGddeZdZdZdZy)zDebugger basicsN)contextmanager) CO_GENERATOR CO_COROUTINECO_ASYNC_GENERATOR)BdbQuitBdb BreakpointceZdZdZy)rz Exception to give up completely.N)__name__ __module__ __qualname____doc__*/opt/alt/python312/lib64/python3.12/bdb.pyrrs*rrcBeZdZdZd1dZdZdZedZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZd2dZdZd1dZdZdZdZd1dZdZdZdZ d3dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*d)Z+d*Z,d+Z-d4d,Z.d5d-Z/d5d.Z0d/Z1d0Z2y)6raGeneric 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. Nc|r t|nd|_i|_i|_d|_d|_|j yN)setskipbreaksfncacheframe_returning enterframe _load_breaks)selfrs r__init__z Bdb.__init__ s:!%CI4   # rc|d|ddzdzk(r|S|jj|}|sMtjj |}tjj |}||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)rfilenamecanonics rr)z Bdb.canonic)sq sXa^+c1 1O,,""8,ggooh/Ggg&&w/G%,DLL "rc^ddl}|jd|_|jddy)z5Set values of attributes as ready to start debugging.rN) linecache checkcachebotframe _set_stopinfo)rr+s rresetz Bdb.reset:s(  4&rc#0K||_dd|_ywr)rrframes rset_enterframezBdb.set_enterframeAs scX|j|5|jr dddy|dk(r|j|cdddS|dk(r|j||cdddS|dk(r|j ||cdddS|dk(r|j ||cdddS|dk(r|j cdddS|dk(r|j cdddS|dk(r|j cdddStd t||j cdddS#1swYyxYw) 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. Nlinecallreturn exceptionc_call c_exceptionc_returnz*bdb.Bdb.dispatch: unknown debugging event:) r3quitting dispatch_line dispatch_calldispatch_returndispatch_exceptiontrace_dispatchprintrepr)rr2eventargs rrAzBdb.trace_dispatchGs2  '}}( '))%0 ( ' ))%5 ( ' ++E37( ' #..uc:( ' **( ' %**( ' "**!( '" >U L&&%( ' 's:D D D (D D (D D D 6 D  D)c|j|s|j|r#|j||jrt|j S)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<rrAr1s rr=zBdb.dispatch_linets> >>% DOOE$: NN5 !}}Gm"""rcd|j|j|_|jS|j|s|j |sy|j r)|j jtzr |jS|j|||jrt|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_backrArGbreak_anywhere stopframef_codeco_flagsGENERATOR_AND_COROUTINE_FLAGS user_callr<rrr2rEs rr>zBdb.dispatch_calls == !LLDM&& &u%)<)>ell336SS&& & uc" ==-"""rc|j|s||jk(r|jr)|jjt zr |j S ||_|j||d|_|jrt|j|ur!|jdk7r|jdd|jdk7r|j||j S#d|_wxYw)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!)rG returnframerMrNrOrPrAr user_returnr<r stoplinenor._set_caller_tracefuncrRs rr?zBdb.dispatch_returns >>% ET-=-=$=~~%,,"7"7:W"W*** ,',$  ,'+$}}Gm~~&4??b+@""4."$**51"""(,$s C$$ C-c|j|r]|jjtzr|dtur|d$|j |||j rt|jS|jrj||jur\|jjjtzr5|dttfvr$|j |||j rt|jS)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) rGrNrOrP StopIterationuser_exceptionr<rrM GeneratorExitrArRs rr@zBdb.dispatch_exceptions >>% LL)),IIA-/CFN##E3/==-""" nndnn!<NN))225RRF}m<<   s +}}Gm"""rc\|y|jD]}tj||syy)z4Return True if module_name matches any skip pattern.FT)rfnmatch)r module_namepatterns ris_skipped_modulezBdb.is_skipped_modules/  yyG{G4!rc|jr+|j|jjdry||jur)|j dk(ry|j |j k\S|jsyy)z>Return True if frame is below the starting frame in the stack.r Fr!T)rra f_globalsr#rMrVf_linenor1s rrGz Bdb.stop_heresf 99%%eoo&9&9*&EF DNN ""$>>T__4 4~~rc|j|jj}||jvry|j}||j|vr(|jj }||j|vryt |||\}}|rD|j|_|r0|jr$|jt|jyy)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)rN co_filenamerrdco_firstlineno effectivenumber currentbp temporarydo_clearstr)rr2r(linenobpflags rrHzBdb.break_heres << 8 89 4;; & X. .\\00FT[[22x7 T YYDN c"))n-rctd)zlRemove temporary breakpoint. Must implement in derived classes or get NotImplementedError. z)subclass of bdb must implement do_clear())NotImplementedError)rrEs rrlz Bdb.do_clears ""MNNrcd|j|jj|jvS)zEReturn True if there is any breakpoint for frame's filename. )r)rNrfrr1s rrLzBdb.break_anywhere s&||ELL445DDrcy)z&Called if we might stop in a function.Nr)rr2 argument_lists rrQz Bdb.user_call rcy)z'Called when we stop or break at a line.Nrr1s rrIz Bdb.user_linervrcy)z&Called when a return trap is set here.Nr)rr2 return_values rrUzBdb.user_returnrvrcy)z$Called when we stop on an exception.Nr)rr2exc_infos rr[zBdb.user_exceptionrvrc<||_||_d|_||_y)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)rMrTr<rV)rrMrTrVs rr.zBdb._set_stopinfo"s##& %rc||j}|r.|js!||jur|j|_yyyyr)rKf_tracer-rA)r current_frame caller_frames rrWzBdb._set_caller_tracefunc0s> %++  4 4T]]9Z#'#6#6L :[ 4^^a'F 5%0rc(|jddy)zStop after one line of code.Nr.rs rset_stepz Bdb.set_stepEs 4&rc(|j|dy)z2Stop on the next line in or below the given frame.Nrr1s rset_nextz Bdb.set_nextIs 5$'rc|jjtzr|j|ddy|j|j|y)z)Stop when returning from the given frame.Nr!)rNrOrPr.rKr1s r set_returnzBdb.set_returnMs; << #@ @   udB /   u||U 3rctjd|tjj}|j |j |5|r'|j |_||_|j}|r'|jdddtj|j y#1swY)xYw)znStart debugging from frame. If frame is not specified, debugging starts from caller's frame. N) syssettrace _getframerKr/r3rAr~r-rr1s r set_tracez Bdb.set_traceTs T =MMO**E   ' $ 3 3 %   MMO ( T(() ( 's)B9B99Cc"|j|jdd|jsftjdtj j }|r0||jur!|`|j }|r||juryyyyy)zStop only at breakpoints or when finished. If there are no breakpoints, set the system trace function to None. Nr!)r.r-rrrrrKr~r1s r set_continuezBdb.set_continueesv 4==$3{{ LL MMO**EE6M E6%6% rcl|j|_d|_d|_t j dy)zuSet quitting attribute to True. Raises BdbQuit exception in the next call to a dispatch_*() method. NT)r-rMrTr<rrrs rset_quitz Bdb.set_quitts*   Trch|jj|g}||vr|j|yy)z/Add breakpoint to breaks, if not already there.N)r setdefaultappend)rr(rn bp_linenoss r_add_to_breakszBdb._add_to_breakss3[[++Hb9  #   f % $rc$|j|}ddl}|j||}|sd||fzS|j||t |||||}|j } | r1|j | r|j| _| j} | r1y)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+getlinerr rrLrAr~rK) rr(rnrkcondfuncnamer+r5ror2s r set_breakz Bdb.set_breaks<<)  62.(F1CC C Hf- &)T8 D""5) $ 3 3 LLErcttjjD]\}}|j||y)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 bplistkeysrrr(rns rrzBdb._load_breakss2#-"3"3"8"8": Xv   & 1#;rc||ftjvr|j|j||j|s|j|=yy)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)r rrremovers r _prune_breakszBdb._prune_breakssK f Z%6%6 6 KK ! ( ( 0{{8$ H%%rc|j|}||jvrd|zS||j|vrd||fzStj||fddD]}|j |j ||y)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)rr rdeleteMer)rr(rnros r clear_breakzBdb.clear_breaks <<) 4;; &3h> > X. .4&7II I##Hf$45a8B KKM9 8V,rc |j|}|j|j |j |j y#t$r}t|cYd}~Sd}~wwxYw)zxDelete a breakpoint by its index in Breakpoint.bpbynumber. If arg is invalid, return an error message. N)get_bpbynumber ValueErrorrmrrfiler5)rrEroerrs rclear_bpbynumberzBdb.clear_bpbynumbersX  $$S)B  277BGG,  s8O sA A( A#A(#A(c|j|}||jvrd|zS|j|D].}tj||f}|D]}|j 0|j|=y)z`Delete all breakpoints in filename. If none were set, return an error message. rN)r)rr rr)rr(r5blistros rclear_all_file_breakszBdb.clear_all_file_breaksst <<) 4;; &3h> >KK)D%%hn5E * KK !rc||jsytjD]}|s|ji|_y)z]Delete all existing breakpoints. If none were set, return an error message. zThere are no breakpointsN)rr bpbynumberr)rros rclear_all_breakszBdb.clear_all_breakss6 {{-''B ( rc|s td t|} tj|}|td|z|S#t$rtd|zdwxYw#t$rtd|zdwxYw)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)rintr r IndexError)rrEriros rrzBdb.get_bpbynumbers 9: : QXF U&&v.B : "m LL!**akk2 3 Am 9As5zA~&Aaxrcddl}ddl}|\}}|j|jj}|d|d}|jj r||jj z }n|dz }|dz }d|j vr(|j d} |dz }||j| z }|7|j|||j} | r||| jzz }|S||d z }|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). rN()zz() __return__z->zWarning: lineno is None) r+reprlibr)rNrfco_namef_localsrCrrcstrip) r frame_linenolprefixr+rr2rnr(srvr5s rformat_stack_entryzBdb.format_stack_entryBs "$ v<< 8 89 & ) <<   %% %A OA T  5>> ) -B IA b! !A  $$XvuGDWtzz|++ G934 4Arc||ddl}|j}||}|jt|tr t |dd}t j|j t|||d|_ t jdy#t$rY(wxYw#d|_ t jdwxYw)zDebug a statement executed via the exec() function. globals defaults to __main__.dict; locals defaults to globals. NrzexecT) __main____dict__r/ isinstancermcompilerrrArrr<)rcmdglobalslocalsrs rrunzBdb.runds ? ''G >F c3 #z62C T(()  gv &!DM LL     !DM LL s$$ B BBBBB;c||ddl}|j}||}|jtj|j  t |||d|_tjdS#t$rYnwxYw d|_tjdy#d|_tjdwxYw)zDebug an expression executed via the eval() function. globals defaults to __main__.dict; locals defaults to globals. NrT) rrr/rrrAevalr<r)rexprrrrs rrunevalz Bdb.runevalzs ? ''G >F  T(() gv.!DM LL       DM LL !DM LL s$ A00 A<9B;A<<BB;c*|j|||y)z.For backwards-compatibility. Defers to run().N)r)rrrrs rrunctxz Bdb.runctxs gv&rc|jtj|jd} ||i|}d|_tjd|S#t$rY)wxYw#d|_tjdwxYw)zWDebug a single function call. Return the result of the function call. NT)r/rrrArr<)rfuncargskwdsress rruncallz Bdb.runcalls|  T(() %%C!DM LL     !DM LL s#A A%"A($A%%A((Br)rFNN)z: NN)3r r r rrr)r/rr3rAr=r>r?r@rarGrHrlrLrQrIrUr[r.rWrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrs  "' +'Z ##,#6#> 6OE     %71'(4*" %"& AE0 2 &"   (, 6 .D,('rrc4tjy)z>DD <<'>D'>D, T04 4990FF 99 DII7 7C ;; , ~= =C 99yy1} 9TYYOK KC rcTd|jd|jd|jS)z1Return a condensed description of the breakpoint.z breakpoint z at :)rirr5rs r__str__zBreakpoint.__str__s+/;; 499MMrrr)r r r rrrrr staticmethodrrrrrrrrrrr r sR( D FJ-('' #)<Nrr c|js|j|jk7ryy|jj|jk7ry|j s|j|_|j |jk7ryy)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)rr5rdrNrr)br2s r checkfuncnamer&sm :: 66U^^ # ||qzz) ' '',~~$##u~~5 rctj||f}|D]}|jst||s|xjdz c_|j s+|j dkDr|xj dzc_c|dfcS t|j |j|j}|r+|j dkDr|xj dzc_n|dfcSy#|dfcYcSxYw)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. r rTFr) r rrrrrrrrcr)rr5r2 possiblesrvals rrhrhFs!!$*-I yy Q&  ! vvxx!|A 4y  "1665??ENNCxx!|A !"4y(5D   "5z!s ACC'c$eZdZdZdZdZdZy)TdbcR|jj}|sd}td||y)N???z+++ call)rNrrB)rr2rnames rrQz Tdb.user_call|s$||##ET j$%rc (ddl}|jj}|sd}|j|jj}|j ||j |j}td||j |d|jy)Nrrz+++r) r+rNrr)rfrrdrcrBr)rr2r+rfnr5s rrIz Tdb.user_linesk||##ET \\%,,22 3  U^^U__E eRsDJJLArctd|y)Nz +++ returnrB)rr2retvals rrUzTdb.user_returns  lF#rc<td||jy)Nz +++ exception)rBr)rr2 exc_stuffs rr[zTdb.user_exceptions oy) rN)r r r rQrIrUr[rrrrr{s&B$rrcRtd|dt|dz}td|y)Nzfoo(r z bar returned)rBbar)nxs rfoor(s% &!S AbD A .!rc&td|d|dz S)Nzbar(rrYr)as rr%r%s &!S Q3Jrc:t}|jdy)Nzimport bdb; bdb.foo(10))rr)rs rtestr,s AEE #$r)rr^rr$ contextlibrinspectrrr__all__rP Exceptionrrrr rrhrr(r%r,rrrr1s %BB * ,| ;>P P+i+R R j uNuNt@0j#$ %r