[:[@sdZddlZddlZddlZddlmZdddgZGdddeZGdddZ d d Z Gd ddZ d d Z ddZ Gddde ZddZddZddZdS)zDebugger basicsN) CO_GENERATORBdbQuitBdb Breakpointc@seZdZdZdS)rz Exception to give up completely.N)__name__ __module__ __qualname____doc__r r /usr/lib/python3.4/bdb.pyr s c@s2eZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&d'Zdd(d)Zd*d+Zd,d-Zd.d/Zdd0d1Zd2d3Zd4d5Zd6ddd7d8Zd9d:Zd;d<Zd=d>Z d?d@Z!dAdBZ"dCdDZ#dEdFZ$dGdHZ%dIdJZ&dKdLZ'dMdNZ(dOdPdQZ)dddRdSZ*dddTdUZ+dVdWZ,dXdYZ-dS)ZrzGeneric 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. NcCs:|rt|nd|_i|_i|_d|_dS)N)setskipbreaksfncacheframe_returning)selfr r r r __init__s  z Bdb.__init__cCsr|d|dddkr"|S|jj|}|sntjj|}tjj|}||j|)rgetospathabspathnormcase)rfilenamecanonicr r r rsz Bdb.canoniccCs3ddl}|jd|_|jdddS)Nr) linecache checkcachebotframe _set_stopinfo)rrr r r reset&s   z Bdb.resetcCs|jr dS|dkr&|j|S|dkrB|j||S|dkr^|j||S|dkrz|j||S|dkr|jS|dkr|jS|dkr|jStdt||jS) NlinecallreturnZ 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_dispatchcCsG|j|s|j|r@|j||jr@tq@n|jS)N) stop_here break_here user_liner&rr+)rr.r r r r'@s   zBdb.dispatch_linecCs|jdkr"|j|_|jS|j|p=|j|sDdS|jrd|jjt@rd|jS|j |||j rt n|jS)N) r f_backr+r0break_anywhere stopframef_codeco_flagsr user_callr&r)rr.r/r r r r(Fs  zBdb.dispatch_callc Cs|j|s||jkr|jr>|jjt@r>|jSz||_|j||Wdd|_X|j rzt n|j|kr|j dkr|j ddqn|jS)Nrr) r0 returnframer5r6r7rr+r user_returnr&r stoplinenor!)rr.r/r r r r)Vs   zBdb.dispatch_returncCs|j|rg|jjt@o<|dtko<|ddks|j|||jrdtqdqnf|jr||jk r|jjjt@r|dtt fkr|j|||jrtqn|j S)Nr) r0r6r7r StopIterationuser_exceptionr&rr5 GeneratorExitr+)rr.r/r r r r*fs   zBdb.dispatch_exceptioncCs.x'|jD]}tj||r dSq WdS)NTF)r fnmatch)rZ module_namepatternr r r is_skipped_moduleszBdb.is_skipped_modulecCsk|jr(|j|jjdr(dS||jkrZ|jdkrJdS|j|jkS|jsgdSdS)NrFrTr)r rB f_globalsrr5r;f_lineno)rr.r r r r0s  z Bdb.stop_herecCs|j|jj}||jkr(dS|j}||j|krj|jj}||j|krjdSnt|||\}}|r|j|_|r|j r|j t |jndSdSdS)NFT) rr6 co_filenamerrDco_firstlineno effectivenumberZ currentbp temporarydo_clearstr)rr.rlinenobpZflagr r r r1s   zBdb.break_herecCstddS)Nz)subclass of bdb must implement do_clear())NotImplementedError)rr/r r r rJsz Bdb.do_clearcCs|j|jj|jkS)N)rr6rEr)rr.r r r r4szBdb.break_anywherecCsdS)znThis method is called when there is the remote possibility that we ever need to stop in this function.Nr )rr.Z argument_listr r r r8sz Bdb.user_callcCsdS)z9This method is called when we stop or break at this line.Nr )rr.r r r r2sz Bdb.user_linecCsdS)z5This method is called when a return trap is set here.Nr )rr.Z return_valuer r r r:szBdb.user_returncCsdS)zmThis method is called if an exception occurs, but only if we are to stop at or just below this level.Nr )rr.exc_infor r r r>szBdb.user_exceptionrcCs(||_||_d|_||_dS)NF)r5r9r&r;)rr5r9r;r r r r!s   zBdb._set_stopinfocCs3|dkr|jd}n|j|||dS)zxStop when the line with the line no greater than the current one is reached or when returning from current frameNr)rDr!)rr.rLr r r set_untils z Bdb.set_untilcCsK|jr7|jj}|r7|j r7|j|_q7n|jdddS)zStop after one line of code.N)rr3f_tracer+r!)rZ caller_framer r r set_steps   z Bdb.set_stepcCs|j|ddS)z2Stop on the next line in or below the given frame.N)r!)rr.r r r set_nextsz Bdb.set_nextcCs=|jjt@r&|j|ddn|j|j|dS)z)Stop when returning from the given frame.Nrr)r6r7rr!r3)rr.r r r set_returnszBdb.set_returncCsq|dkrtjj}n|jx(|rR|j|_||_|j}q+W|jtj|jdS)zpStart debugging from `frame`. If frame is not specified, debugging starts from caller's frame. N) sys _getframer3r"r+rQr rRsettrace)rr.r r r set_traces       z Bdb.set_tracecCsm|j|jdd|jsitjdtjj}x+|re||jk re|`|j}q>WndS)Nrr)r!r rrUrWrVr3rQ)rr.r r r set_continues  zBdb.set_continuecCs/|j|_d|_d|_tjddS)NT)r r5r9r&rUrW)rr r r set_quits   z Bdb.set_quitFc Cs|j|}ddl}|j||}|sAd||fS|jj|g}||krr|j|nt|||||} dS)NrzLine %s:%d does not exist)rrgetliner setdefaultappendr) rrrLrIcondfuncnamerr#listrMr r r set_breaks  z Bdb.set_breakcCsJ||ftjkr,|j|j|n|j|sF|j|=ndS)N)rbplistrremove)rrrLr r r _prune_breaks!s zBdb._prune_breakscCs|j|}||jkr&d|S||j|krGd||fSx/tj||fddD]}|jqeW|j||dS)NzThere are no breakpoints in %szThere is no breakpoint at %s:%d)rrrrbdeleteMerd)rrrLrMr r r clear_break's$zBdb.clear_breakcCsiy|j|}Wn/tk rD}zt|SWYdd}~XnX|j|j|j|jdS)N)get_bpbynumber ValueErrorrKrerdfiler#)rr/rMerrr r r clear_bpbynumber3s  zBdb.clear_bpbynumbercCsz|j|}||jkr&d|SxC|j|D]4}tj||f}x|D]}|jqTWq4W|j|=dS)NzThere are no breakpoints in %s)rrrrbre)rrr#ZblistrMr r r clear_all_file_breaks;s zBdb.clear_all_file_breakscCsA|js dSx$tjD]}|r|jqqWi|_dS)NzThere are no breakpoints)rr bpbynumberre)rrMr r r clear_all_breaksEs  zBdb.clear_all_breakscCs|stdnyt|}Wn"tk rItd|YnXytj|}Wn"tk rtd|YnX|dkrtd|n|S)NzBreakpoint number expectedz Non-numeric breakpoint number %sz!Breakpoint number %d out of rangezBreakpoint %d already deleted)rhintrrm IndexError)rr/rHrMr r r rgMs   zBdb.get_bpbynumbercCs/|j|}||jko.||j|kS)N)rr)rrrLr r r get_break\sz Bdb.get_breakcCsH|j|}||jkrD||j|krDtj||fpGgS)N)rrrrb)rrrLr r r get_breaksaszBdb.get_breakscCs1|j|}||jkr)|j|SgSdS)N)rr)rrr r r get_file_breaksgs zBdb.get_file_breakscCs|jS)N)r)rr r r get_all_breaksnszBdb.get_all_breakscCsg}|r'|j|kr'|j}nxB|dk rk|j||jf||jkr_Pn|j}q*W|jtdt|d}x2|dk r|j|j|j f|j}qW|dkrtdt|d}n||fS)Nrr) tb_frametb_nextr]rDr r3reversemaxlen tb_lineno)rftstackir r r get_stackts      z Bdb.get_stackz: c Cs2ddl}ddl}|\}}|j|jj}d||f}|jjrh||jj7}n |d7}d|jkr|jd} nd} | r||j| 7}n |d7}d|jkr|jd} |d7}||j| 7}n|j|||j } | r.||| j 7}n|S)Nrz%s(%r)zZ__args__z()Z __return__z->) rreprlibrr6rEco_namef_localsr-r[rCstrip) rZ frame_linenoZlprefixrrr.rLrsargsrvr#r r r format_stack_entrys*      zBdb.format_stack_entrycCs|dkr$ddl}|j}n|dkr9|}n|jt|trgt|dd}ntj|jz-yt |||Wnt k rYnXWdd|_ tjdXdS)NrzexecT) __main____dict__r" isinstancerKcompilerUrWr+rrr&)rcmdglobalslocalsrr r r runs         zBdb.runcCs|dkr$ddl}|j}n|dkr9|}n|jtj|jz-yt|||SWntk r~YnXWdd|_tjdXdS)NrT) rrr"rUrWr+evalrr&)rexprrrrr r r runevals         z Bdb.runevalcCs|j|||dS)N)r)rrrrr r r runctxsz Bdb.runctxcOsj|jtj|jd}z,y|||}Wntk rJYnXWdd|_tjdX|S)NT)r"rUrWr+rr&)rfuncrkwdsZresr r r runcalls    z Bdb.runcall).rrrr rrr"r+r'r(r)r*rBr0r1rJr4r8r2r:r>r!rPrRrSrTrXrYrZrardrfrkrlrnrgrqrrrsrtrrrrrrr r r r rsX                              cCstjdS)N)rrXr r r r rXsrXc@seZdZdZdZiZdgZdddddZddZd d Z d d Z dd dZ ddZ ddZ dS)raBreakpoint 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. rNFcCs||_d|_||_||_||_||_d|_d|_d|_t j |_ t j d7_ |j j |||f|jkr|j||fj |n|g|j||fs zTdb.user_exceptionN)rrrr8r2r:r>r r r r rs    rcCs1td|dt|d}td|dS)Nzfoo() z bar returned)r,bar)nxr r r foosrcCstd|d|dS)Nzbar(rr<)r,)ar r r rsrcCst}|jddS)Nzimport bdb; bdb.foo(10))rr)r|r r r tests r)r r@rUrinspectr__all__ ExceptionrrrXrrrGrrrrr r r r s     Z  0