QfdZddlZddlZddlZddlmZmZmZgdZeezezZ Gdde Z GddZ d Z Gd d Zd Zd ZGdde ZdZdZdZy)zDebugger basicsN) 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.pyrr s*rrc2eZdZdZd0dZdZdZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZd1dZdZd0dZdZdZdZd0dZdZdZdZ d2dZdZ d Z!d!Z"d"Z#d#Z$d$Z%d%Z&d&Z'd'Z(d(Z)d)Z*d*Z+d3d+Z,d4d,Z-d4d-Z.d.Z/d/Z0y)5raGeneric 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. Ncv|r t|nd|_i|_i|_d|_|j yN)setskipbreaksfncacheframe_returning _load_breaks)selfrs r__init__z Bdb.__init__s3!%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.reset8s(  4&rcz|jry|dk(r|j|S|dk(r|j||S|dk(r|j||S|dk(r|j ||S|dk(r |j S|dk(r |j S|dk(r |j St d t||j S) 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:)quitting dispatch_line dispatch_calldispatch_returndispatch_exceptiontrace_dispatchprintrepr)rframeeventargs rr;zBdb.trace_dispatch?s0 ==  F?%%e, , F?%%eS1 1 H ''s3 3 K **5#6 6 H && & M !&& & J && & :DKH"""rc|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_liner6rr;rr>s rr7zBdb.dispatch_linejs> >>% 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_backr;rBbreak_anywhere stopframef_codeco_flagsGENERATOR_AND_COROUTINE_FLAGS user_callr6rrr>r@s rr8zBdb.dispatch_callvs == !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)rB returnframerIrJrKrLr;r user_returnr6r stoplinenor,_set_caller_tracefuncrNs rr9zBdb.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) rBrJrKrL StopIterationuser_exceptionr6rrI GeneratorExitr;rNs 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 FrT)rr] f_globalsr!rIrRf_linenorEs rrBz 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'rJ co_filenamerr`co_firstlineno effectivenumber currentbp temporarydo_clearstr)rr>r&linenobpflags rrCzBdb.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)rr@s rrhz Bdb.do_clears ""MNNrcd|j|jj|jvS)zEReturn True if there is any breakpoint for frame's filename. )r'rJrbrrEs rrHzBdb.break_anywheres&||ELL445DDrcy)z&Called if we might stop in a function.Nr)rr> argument_lists rrMz Bdb.user_call rcy)z'Called when we stop or break at a line.NrrEs rrDz Bdb.user_line rrrcy)z&Called when a return trap is set here.Nr)rr> return_values rrQzBdb.user_returnrrrcy)z$Called when we stop on an exception.Nr)rr>exc_infos rrWzBdb.user_exceptionrrrc<||_||_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)rIrPr6rR)rrIrPrRs rr,zBdb._set_stopinfos##& %rc^|j}|r|js|j|_yyyr)rGf_tracer;)r current_frame caller_frames rrSzBdb._set_caller_tracefunc&s/ %++  4 4#'#6#6L !5rjs r set_untilz Bdb.set_until2s) >^^a'F 5%0rc(|jddy)zStop after one line of code.Nr,rs rset_stepz Bdb.set_step:s 4&rc(|j|dy)z2Stop on the next line in or below the given frame.NrrEs rset_nextz Bdb.set_next>s 5$'rc|jjtzr|j|ddy|j|j|y)z)Stop when returning from the given frame.Nr)rJrKrLr,rGrEs r set_returnzBdb.set_returnBs; << #@ @   udB /   u||U 3rc|tjj}|j|r'|j|_||_|j}|r'|jtj|jy)znStart debugging from frame. If frame is not specified, debugging starts from caller's frame. N) sys _getframerGr-r;rzr+rsettracerEs r set_tracez Bdb.set_traceIse =MMO**E  //EM!DMLLE  T(()rc"|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+rrrrrGrzrEs r set_continuezBdb.set_continueXsv 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+rIrPr6rrrs rset_quitz Bdb.set_quitgs*   Trch|jj|g}||vr|j|yy)z/Add breakpoint to breaks, if not already there.N)r setdefaultappend)rr&rj bp_linenoss r_add_to_breakszBdb._add_to_breaksxs3[[++Hb9  #   f % $rc|j|}ddl}|j||}|sd||fzS|j||t |||||}y)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) rr&rjrgcondfuncnamer)r/rks r set_breakz Bdb.set_break~s_<<)  62.(F1CC C Hf- &)T8 DrcttjjD]\}}|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)rbplistkeysrrr&rjs 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)rrrremovers 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'rrrdeleteMer)rr&rjrks 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 ValueErrorrirrfiler/)rr@rkerrs 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'rrrr)rr&r/blistrks 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)rrks 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)rintrr IndexError)rr@rerks 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'rJrbco_namef_localsr=rr_strip) r frame_linenolprefixr)rr>rjr&srvr/s rformat_stack_entryzBdb.format_stack_entry-s "$ 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- isinstancericompilerrr;rrr6)rcmdglobalslocalsrs rrunzBdb.runOs ? ''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-rrr;evalr6r)rexprrrrs rrunevalz Bdb.runevales ? ''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.runctxys 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-rrr;rr6)rfuncargskwdsress rruncallz Bdb.runcalls|  T(() %%C!DM LL     !DM LL s#A A%"A($A%%A((Br)rFNN)z: NN)1r r r r rr'r-r;r7r8r9r:r]rBrCrhrHrMrDrQrWr,rSr~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrs "')#V ##,#6#> 6OE     %71'(4 * %"& AE 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 :)rerr/rs r__str__zBreakpoint.__str__ s+/;; 499MMrrr)r r r r rrrr staticmethodrrrrrrr rrrrrsR( D FJ-('' #)<Nrrc|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)rr/r`rJrr)br>s r checkfuncnamersm :: 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. rrTFr) rrrrrrrrr_r)rr/r> possiblesrvals rrdrd1s!!$*-I yy Q&  ! vvxx!|A 4y  "1665??ENNCxx!|A !"4y(5D   "5z!s ACC'c$eZdZdZdZdZdZy)TdbcR|jj}|sd}td||y)N???z+++ call)rJrr<)rr>rnames rrMz Tdb.user_callgs$||##ET j$%rc (ddl}|jj}|sd}|j|jj}|j ||j |j}td||j |d|jy)Nrrz+++r ) r)rJrr'rbrr`r_r<r)rr>r)rfnr/s rrDz Tdb.user_lineksk||##ET \\%,,22 3  U^^U__E eRsDJJLArctd|y)Nz +++ returnr<)rr>retvals rrQzTdb.user_returnrs  lF#rc<td||jy)Nz +++ exception)r<r)rr> exc_stuffs rrWzTdb.user_exceptionts oy) rN)r r r rMrDrQrWrrrrrfs&B$rrcRtd|dt|dz}td|y)Nzfoo(r z bar returned)r<bar)nxs rfoor$xs% &!S AbD A .!rc&td|d|dz S)Nzbar(rrUr)as rr!r!}s &!S Q3Jrc:t}|jdy)Nzimport bdb; bdb.foo(10))rr)rs rtestr(s AEE #$r)r rZrr"inspectrrr__all__rL Exceptionrrrrrrdrr$r!r(rrrr,s BB * ,| ;>P P+i+~ ~ B uNuNt@0j#$ %r