o w[e@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZGdddeZgdZddZdd ZGd d d eZd ZGd ddejejZedurgdZeD]Zeeedejd7Zqqeejj7Z[[d*ddZ d*ddZ!ddZ"ddZ#ddddZ$d+ddZ%dd Z&d!Z'd"d#Z(d$d%Z)d&Z*d'd(Z+e,d)krddl-Z-e-+dSdS),a The Python Debugger Pdb ======================= To use the debugger in its simplest form: >>> import pdb >>> pdb.run('') The debugger's prompt is '(Pdb) '. This will stop in the first function call in . Alternatively, if a statement terminated with an unhandled exception, you can use pdb's post-mortem facility to inspect the contents of the traceback: >>> >>> import pdb >>> pdb.pm() The commands recognized by the debugger are listed in the next section. Most can be abbreviated as indicated; e.g., h(elp) means that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel', nor as 'H' or 'Help' or 'HELP'). Optional arguments are enclosed in square brackets. Alternatives in the command syntax are separated by a vertical bar (|). A blank line repeats the previous command literally, except for 'list', where it lists the next 11 lines. Commands that the debugger doesn't recognize are assumed to be Python statements and are executed in the context of the program being debugged. Python statements can also be prefixed with an exclamation point ('!'). This is a powerful way to inspect the program being debugged; it is even possible to change variables or call functions. When an exception occurs in such a statement, the exception name is printed but the debugger's state is not changed. The debugger supports aliases, which can save typing. And aliases can have parameters (see the alias help entry) which allows one a certain level of adaptability to the context under examination. Multiple commands may be entered on a single line, separated by the pair ';;'. No intelligence is applied to separating the commands; the input is split at the first ';;', even if it is in the middle of a quoted string. If a file ".pdbrc" exists in your home directory or in the current directory, it is read in and executed as if it had been typed at the debugger prompt. This is particularly useful for aliases. If both files exist, the one in the home directory is read first and aliases defined there can be overridden by the local file. This behavior can be disabled by passing the "readrc=False" argument to the Pdb constructor. Aside from aliases, the debugger is not directly programmable; but it is implemented as a class from which you can derive your own debugger class, which you can make as fancy as you like. Debugger commands ================= Nc@seZdZdZdS)RestartzBCauses a debugger to be restarted for the debugged python program.N)__name__ __module__ __qualname____doc__rr/usr/lib/python3.10/pdb.pyrWsr) runpmPdbrunevalrunctxruncall set_trace post_mortemhelpcCstdt|}zt|}Wn tyYdSw|'t|ddD]\}}||r<|||fWdSq%WddS1sHwYdS)Nzdef\s+%s\s*[(])start)recompileescapetokenizeopenOSError enumeratematch)funcnamefilenamecrefplinenolinerrr find_function^s"    r"cCs8tt|}||D] \}}||kr|Sq dSNr)listdisfindlinestartsreverse)codelasti linestartsir rrr lasti2linenoks r,c@seZdZdZddZdS)_rstrz#String that doesn't quote its repr.cCs|SNrselfrrr__repr__vsz_rstr.__repr__N)rrrrr1rrrrr-ts r-z -> c@s(eZdZdZ  dddZddZd d Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6ZeZdd8d9Zd:d;ZeZ eZ!eZ"dd?Z%d@dAZ&dBdCZ'eZ(dDdEZ)eZ*dFdGZ+eZ,dHdIZ-eZ.dJdKZ/e/Z0eZ1eZ2dLdMZ3e3Z4e3Z5dNdOZ6dPdQZ7e7Z8dRdSZ9e9Z:dTdUZ;e;ZdXdYZ?e?Z@dZd[ZAeAZBd\d]ZCeCZDd^d_ZEeEZFZGd`daZHeHZIdbdcZJeZKdddeZLeLZMeLZNdfdgZOdhdiZPePZQdjdkZReRZSdldmZTddndoZUdpdqZVdrdsZWdtduZXdvdwZYeZZeZ[eZ\dxdyZ]e]Z^dzd{Z_e_Z`d|d}ZaeZbdddZcddZdeZeddZfeZgddZhddZiddZjddZkddZlddZmgdZnddZoepfddZqddZrerZsddZtddZuddZvddZwddZxdS)r NtabFTc Cs\tjj||dtj||||td|rd|_d|_i|_ i|_ d|_ d|_ i|_ z ddl}|dWn tyAYnwd|_||_g|_|rz ttjd}|j|Wdn1sgwYWn tyvYnwztd }|j|Wdn1swYWn tyYnwi|_i|_i|_d|_d|_dS) N)skipzpdb.Pdbrz(Pdb) Fz `@#$%^&*()=+[{]}\|;:'",<>?z~/.pdbrcz.pdbrc)bdbBdb__init__cmdCmdsysaudit use_rawinputpromptaliases displaying mainpyfile_wait_for_mainpyfile tb_linenoreadlineset_completer_delims ImportError allow_kbdintnosigintrcLinesrospath expanduserextendrcommandscommands_dopromptcommands_silentcommands_defining commands_bnum) r0 completekeystdinstdoutr3rGreadrcrCrcFilerrrr7sT      z Pdb.__init__cCs*|jrt|d|||dS)Nz- Program interrupted. (Use 'cont' to resume).)rFKeyboardInterruptmessageset_stepr)r0signumframerrrsigint_handlers  zPdb.sigint_handlercCstj||dSr.)r5r6resetforgetr/rrrr]s  z Pdb.resetcCs&d|_g|_d|_d|_|jdSr#)r stackcurindexcurframerBclearr/rrrr^s z Pdb.forgetcCsj||||\|_|_|r#t|jj|j}||j|j<|j }|s|j|jd|_ |j j |_ | Sr#)r^ get_stackr_r`r,tb_framef_codetb_lastirBtb_nextraf_localscurframe_locals execRcLines)r0ftbr rrrsetups  z Pdb.setupcCsj|jsdS|j}|g|_|r3|}|r/|ddkr/||r/|jt|7_dS|sdSdS)Nr#T)rHr'popstriponecmdreversed)r0rHr!rrrrjs   zPdb.execRcLinescCs2|jrdS||r|d||ddSdS)znThis method is called when there is the remote possibility that we ever need to stop in this function.Nz--Call--)rA stop_hererX interaction)r0r[ argument_listrrr user_calls   z Pdb.user_callcCsL|jr|j||jjks|jdkrdSd|_||r$||ddSdS)z;This function is called when we stop or break at this line.rNF)rAr@canonicre co_filenamef_lineno bp_commandsrt)r0r[rrr user_lines  z Pdb.user_linecCst|ddrH|j|jvrH|j}d|_|j}||d|j|D]}||q ||_|j|s9||j|j |j |rB| | dSdS)zCall every command that was set for the current active breakpoint (if there is one). Returns True if the normal interaction function must be called, False otherwise. currentbpFrNr) getattrr|rMlastcmdrmrqrOprint_stack_entryr_r`rN_cmdloopr^)r0r[r| lastcmd_backr!rrrrzs      zPdb.bp_commandscCs.|jrdS||jd<|d||ddS)z7This function is called when a return trap is set here.N __return__z --Return--)rArhrXrt)r0r[ return_valuerrr user_returns   zPdb.user_returncCsh|jrdS|\}}}||f|jd<|s|turdnd}|d|t||df|||dS)zoThis function is called if an exception occurs, but only if we are to stop at or just below this level.N __exception__z Internal r4z%s%s)rArh StopIterationrX tracebackformat_exception_onlyrprt)r0r[exc_infoexc_type exc_value exc_tracebackprefixrrruser_exceptions zPdb.user_exceptioncCs< z d|_|d|_WdSty|dYnwq)NTFz--KeyboardInterrupt--)rFcmdlooprWrXr/rrrr3s z Pdb._cmdloopcCsb|j|j}|r-|D]!\}}||}||ur,||kr,|||<|d|||fq dSdS)Nzdisplay %s: %r [old: %r])r?getraitems_getval_exceptrX)r0r?exproldvaluenewvaluerrrpreloop@s z Pdb.preloopcCsrtjrz ttjtjWn tyYnwdt_|||r&|dS||j|j | |dSr.) r _previous_sigint_handlersignalSIGINT ValueErrorrmr^rr_r`r)r0r[rrrrrtMs   zPdb.interactioncCs|dur |t|dSdS)z{Custom displayhook for the exec in default(), which prevents assignment of the _ variable in the builtins. N)rXrepr)r0objrrr displayhook_szPdb.displayhookcCs|dddkr|dd}|j}|jj}z;t|ddd}tj}tj}tj}z|jt_|jt_|jt_t|||W|t_|t_|t_WdS|t_|t_|t_w| YdS)Nr! zsingle) rira f_globalsrr:rTrSrexec _error_exc)r0r!localsglobalsr( save_stdout save_stdinsave_displayhookrrrdefaultgs* z Pdb.defaultcCs|s|S|}|d|jvrI|j|d}d}|ddD]}|dt||}|d7}q |dd|dd}|}|d|jvs|ddkrp|d}|dkrp||d d}|j ||d| }|S) z*Handle alias expansion and ';;' separator.rrN%z%* aliasz;;) rpsplitr>replacestrjoinfindlstripcmdqueueappendrstrip)r0r!argsiitmpArgmarkernextrrrprecmd|s*   z Pdb.precmdcCs|js tj||S||S)zInterpret the argument as though it had been typed in response to the prompt. Checks whether this line is typed at the normal prompt or in a breakpoint command list definition. )rPr8r9rqhandle_command_def)r0r!rrrrqs z Pdb.onecmdcCs||\}}}|s dS|dkrd|j|j<dS|dkr!g|_dS|j|j}|r3||d|n||z t|d|}Wn tyM|j}Ynw|j |j vr_d|j |j<g|_dSdS) z8Handles one command line during command list definition.NsilentTendrrdo_F) parselinerOrQrrMrr}AttributeErrorrrcommands_resumingrN)r0r!r8argcmdlistfuncrrrrs.       zPdb.handle_command_defcCst||jddS)NfileprintrTr0msgrrrrXz Pdb.messagecCstd||jddS)Nz***rrrrrrerrorz Pdb.errorcCs|dr gSz |||||}Wn tyg}Ynwtt|d}|D]$}tj|r;| |dq+tj |rO| drO| |dq+|S)N):,*/).pyz.pywr) rpendswith_complete_expression ExceptionglobrrIrJisdirrisfilelower)r0textr!begidxendidxretglobsfnrrr_complete_locations  zPdb._complete_locationcsfddttjjDS)Ncs.g|]\}}|durt|rt|qSr.)r startswith).0r+bprrr s z*Pdb._complete_bpnumber..)rr5 Breakpoint bpbynumberr0rr!rrrrr_complete_bpnumberszPdb._complete_bpnumberc s|jsgSi|jj|j}dvrRdz|d}ddD]}t||}q$Wn ttfy:gYSwddddfddt|DSfdd| DS)N.rrrcs"g|] }|dr|qS)rrrn)dottedrrrrs"z,Pdb._complete_expression..cg|] }|r|qSrrrrrrr) rarrirr}KeyErrorrrdirkeys)r0rr!rrnsrpartr)rrrrrs    zPdb._complete_expressioncCsB|s ttjjd}nzt|}Wn |dYdS||_||jvr4|j||j||j |f}nd}g|j|<d|j|<d|j |<|j }d|_ d|_ zKz| Wn2t y|rt|d|j|<|d|j|<|d|j |<n |j|=|j|=|j |=|d Yn wWd|_ ||_ dSWd|_ ||_ dSd|_ ||_ w) a4commands [bpnumber] (com) ... (com) end (Pdb) Specify a list of commands for breakpoint number bpnumber. The commands themselves are entered on the following lines. Type a line containing just 'end' to terminate the commands. The commands are executed when the breakpoint is hit. To remove all commands from a breakpoint, type commands and follow it immediately with end; that is, give no commands. With no bpnumber argument, commands refers to the last breakpoint set. You can use breakpoint commands to start your program up again. Simply use the continue command, or step, or any other command that resumes execution. Specifying any command resuming execution (currently continue, step, next, return, jump, quit and their abbreviations) terminates the command list (as if that command was immediately followed by end). This is because any time you resume execution (even with a simple next or step), you may encounter another breakpoint -- which could have its own command list, leading to ambiguities about which list to execute. If you use the 'silent' command in the command list, the usual message about stopping at a breakpoint is not printed. This may be desirable for breakpoints that are to print a specific message and then continue. If none of the other commands print anything, you will see no sign that the breakpoint was reached. rz.Usage: commands [bnum] ... endNTFz(com) rrz1command definition aborted, old commands restored)lenr5rrintrrQrMrNrOr=rPrrW)r0rbnumold_command_defs prompt_backrrr do_commandssP%          zPdb.do_commandsrc Cs,|s|jr|dtjjD] }|r||qdSd}d}d}|d}|dkr=||dd}|d|}| d}d} |dkr|d|}| |} | s`| d|dS| }||dd}zt |}Wnit y| d|YdSwzt |}WnQt yz t||jj|j} Wn|} Yzt| d r| j} | j} | j} | j}| j}Wn||\} }}| s| d |YYdS| } t |}YYnw|s|}|||}|r|||||| }|r| |dS|||d }|d |j|j|jfdSdS) ab(reak) [ ([filename:]lineno | function) [, condition] ] Without argument, list all breaks. With a line number argument, set a break at this line in the current file. With a function name, set a break at the first executable line of that function. If a second argument is present, it is a string specifying an expression which must evaluate to true before the breakpoint is honored. The line number may be prefixed with a filename and a colon, to specify a breakpoint in another file (probably one that hasn't been loaded yet). The file is searched for on sys.path; the .py suffix may be omitted. z!Num Type Disp Enb WhereNrrrrz%r not found from sys.pathzBad lineno: %s__func__zJThe specified object %r is not a function or was not found along sys.path.rzBreakpoint %d at %s:%d) breaksrXr5rrbpformatrrrrfind lookupmodulerrrevalrarrihasattrr__code__co_nameco_firstlinenorxlineinfo defaultFile checkline set_break get_breaksnumberrr!)r0r temporaryrrr condcommacolonrrkrr(oklnr!errrrrdo_breakNs              z Pdb.do_breakcCs"|jjj}|dkr|jr|j}|S)zProduce a reasonable default.z)rarerxr@)r0rrrrr s zPdb.defaultFilecCs||ddS)ztbreak [ ([filename:]lineno | function) [, condition] ] Same arguments as break, but sets a temporary breakpoint: it is automatically deleted when first hit. rN)rr0rrrr do_tbreaksz Pdb.do_tbreakc Csd}|d}t|dkr|d}nt|dkr!|d}n|S|dkr)|S|d}|ddkr?|d=t|dkr?|S|}t|dkrN|d}n||d}|rY|}|d}t||} | pe|S) N)NNN'rrr4rr0)rrrpr rr") r0 identifierfailedidstringidpartsfnameitemrkanswerrrrr s,          z Pdb.lineinfocCst|dd}|r |jnd}t|||}|s|ddS|}|r9|ddks9|dddks9|dddkr@|d dS|S) zCheck whether specified line seems to be executable. Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank line or EOF). Warning: testing is not comprehensive. raNz End of filerrnrz"""z'''zBlank or comment)r}r linecachegetlinerXrpr)r0rr r[rr!rrrr s    z Pdb.checklinec Cj|}|D],}z||}Wnty&}z ||WYd}~qd}~ww||d|qdS)zenable bpnumber [bpnumber ...] Enables the breakpoints given as a space separated list of breakpoint numbers. Nz Enabled %s)rget_bpbynumberrrenablerXr0rrr+rrrrr do_enablesz Pdb.do_enablec Cr%)aNdisable bpnumber [bpnumber ...] Disables the breakpoints given as a space separated list of breakpoint numbers. Disabling a breakpoint means it cannot cause the program to stop execution, but unlike clearing a breakpoint, it remains in the list of breakpoints and can be (re-)enabled. Nz Disabled %s)rr&rrdisablerXr(rrr do_disableszPdb.do_disablec Cs|dd}z|d}Wn tyd}Ynwz ||d}Wn&ty2|dYdStyI}z ||WYd}~dSd}~ww||_|sY|d|jdS|d|jdS)a#condition bpnumber [condition] Set a new condition for the breakpoint, an expression which must evaluate to true before the breakpoint is honored. If condition is absent, any existing condition is removed; i.e., the breakpoint is made unconditional. rrNrBreakpoint number expectedz#Breakpoint %d is now unconditional.z$New condition set for breakpoint %d.) r IndexErrorr&rprrrrXr)r0rrrrrrrr do_conditions$    zPdb.do_conditionc Cs|}z t|d}Wnd}Yz ||d}Wn&ty/|dYdStyF}z ||WYd}~dSd}~ww||_|dkre|dkrWd|}nd}|d||j fdS|d|j dS) aignore bpnumber [count] Set the ignore count for the given breakpoint number. If count is omitted, the ignore count is set to 0. A breakpoint becomes active when the ignore count is zero. When non-zero, the count is decremented each time the breakpoint is reached and the breakpoint is not disabled and any associated condition evaluates to true. rrr,Nz %d crossingsz 1 crossingz%Will ignore next %s of breakpoint %d.z-Will stop next time breakpoint %d is reached.) rrrpr&r-rrignorerXr)r0rrcountrrcountstrrrr do_ignore7s0     z Pdb.do_ignorec Cs|s9ztd}Wn tyd}Ynw|}|dvr7ddtjjD}||D] }|d|q-dSd|vr| d}|d|}||d d}zt |}Wn t ycd |}Ynw| ||dd}| ||}|r}||dS|D] }|d|qdS|} | D]-}z||}Wnt y}z ||WYd}~qd}~ww|||d|qdS) a=cl(ear) filename:lineno cl(ear) [bpnumber [bpnumber...]] With a space separated list of breakpoint numbers, clear those breakpoints. Without argument, clear all breaks (but first ask confirmation). With a filename:lineno argument, clear all breaks at that line in that file. zClear all breaks? no)yyescSsg|]}|r|qSrr)rrrrrrhsz Pdb.do_clear..z Deleted %sNrrzInvalid line number (%s))inputEOFErrorrprr5rrclear_all_breaksrXrrrr  clear_breakrrr&clear_bpbynumber) r0rreplybplistrr+rr r numberlistrrrdo_clearZsR           z Pdb.do_clearcC |dS)zw(here) Print a stack trace, with the most recent frame at the bottom. An arrow indicates the "current frame", which determines the context of most commands. 'bt' is an alias for this command. N)print_stack_tracerrrrdo_wheres z Pdb.do_wherecCs`d|krt|jksJJ||_|j|jd|_|jj|_||j|jd|_dSr#)rr_r`rarhrirr )r0rrrr _select_frames "  zPdb._select_framecCsx|jdkr |ddSzt|pd}Wnty%|d|YdSw|dkr-d}ntd|j|}||dS)zu(p) [count] Move the current frame count (default one) levels up in the stack trace (to an older frame). rz Oldest frameNrInvalid frame count (%s))r`rrrmaxrBr0rr0newframerrrdo_ups   z Pdb.do_upcCs|jdt|jkr|ddSzt|pd}Wnty*|d|YdSw|dkr7t|jd}n tt|jd|j|}||dS)zd(own) [count] Move the current frame count (default one) levels down in the stack trace (to a newer frame). rz Newest frameNrCr)r`rr_rrrminrBrErrrdo_downs  z Pdb.do_downcCsf|r(zt|}Wnty|d|YdSw||jjkr'|ddSnd}||j|dS)aNunt(il) [lineno] Without argument, continue execution until the line with a number greater than the current one is reached. With a line number, continue execution until a line with a number greater or equal to that is reached. In both cases, also stop when the current frame returns. Error in argument: %rNz7"until" line number is smaller than current line numberr)rrrrary set_until)r0rr rrrdo_untils    z Pdb.do_untilcCr?)zs(tep) Execute the current line, stop at the first possible occasion (either in a function that is called or in the current function). r)rYrrrrdo_stepsz Pdb.do_stepcC||jdS)zxn(ext) Continue execution until the next line in the current function is reached or it returns. r)set_nextrarrrrdo_nexts z Pdb.do_nextc Csv|r9ddl}tjdd}z||t_Wnty1}z|d||fWYd}~dSd}~ww|tjdd<t)arun [args...] Restart the debugged python program. If a string is supplied it is split with "shlex", and the result is used as the new sys.argv. History, breakpoints, actions and debugger options are preserved. "restart" is an alias for "run". rNrzCannot run %s: %s)shlexr:argvrrrr)r0rrQargv0errrdo_runsz Pdb.do_runcCrN)zPr(eturn) Continue execution until the current function returns. r) set_returnrarrrr do_returns z Pdb.do_returncCs<|jsz ttj|jt_Wn tyYnw|dS)z]c(ont(inue)) Continue execution, only stop when a breakpoint is encountered. r)rGrrr\r rr set_continuerrrr do_continues zPdb.do_continuec Cs|jdt|jkr|ddSzt|}Wnty&|dYdSwz||j_|j|jd|f|j|j<||j|jWdSty_}z|d|WYd}~dSd}~ww)aj(ump) lineno Set the next line that will be executed. Only available in the bottom-most frame. This lets you jump back and execute code again, or jump forward to skip code that you don't want to run. It should be noted that not all jumps are allowed -- for instance it is not possible to jump into the middle of a for loop or out of a finally clause. rz)You can only jump within the bottom frameNz)The 'jump' command requires a line numberrzJump failed: %s) r`rr_rrrraryr)r0rrTrrrdo_jump!s    z Pdb.do_jumpcCstd|jj}|j}t|j|j|j}d|j |_ | dz t |j |||fWn ty;|Ynw| dt|j|j|_dS)zdebug code Enter a recursive debugger that steps through the code argument (which is an arbitrary expression or statement to be executed in the current environment). Nz(%s) zENTERING RECURSIVE DEBUGGERzLEAVING RECURSIVE DEBUGGER)r:settracerarrir rRrSrTr=rprX call_tracingr rrtrace_dispatchr~)r0rrrprrrdo_debug>s       z Pdb.do_debugcCsd|_|dS)z[q(uit) exit Quit from the debugger. The program being executed is aborted. Tr)_user_requested_quitset_quitrrrrdo_quitTsz Pdb.do_quitcCs|dd|_|dS)z=EOF Handles the receipt of EOF as a command. r4Tr)rXr`rarrrrdo_EOF_s z Pdb.do_EOFcCs|jj}|j}|j|j}|jtj@r|d}|jtj@r!|d}t |D]}|j |}||vr<| d|||fq%| d|fq%dS)zHa(rgs) Print the argument list of the current function. rz%s = %rz%s = *** undefined ***N) rareri co_argcountco_kwonlyargcountco_flagsinspect CO_VARARGSCO_VARKEYWORDSrange co_varnamesrX)r0rcodictrr+namerrrdo_argshs   z Pdb.do_argscCs0d|jvr|t|jddS|ddS)zQretval Print the return value for the last return of a function. rzNot yet returned!N)rirXrrrrrr do_retvalys z Pdb.do_retvalcCs&z t||jj|jWS|r.)rrarrirrrrr_getvals z Pdb._getvalcCshz|durt||jj|jWSt||j|jWStdd}tj|d }t d|YS)Nrrz** raised %s **) rrarrirhr:rrrrpr-)r0rr[rrrrrrszPdb._getval_exceptcCs,tdd}|tj|ddS)Nrr)r:rrrrrp)r0rrrrrszPdb._error_exccCsFz||}WnYdSz |||WdS|YdSr.)rqrXr)r0rrvalrrr _msg_val_funcszPdb._msg_val_funccCs||tdS)z@p expression Print the value of the expression. N)rsrrrrrdo_pszPdb.do_pcCs||tjdS)zHpp expression Pretty-print the value of the expression. N)rspprintpformatrrrrdo_ppsz Pdb.do_ppcCsd|_d}|rL|dkrLz/d|vr,|d\}}t|}t|}||kr+||}n t|}td|d}Wn)tyK|d|YdSw|jdusU|dkr_td|jj d}n|jd}|durl|d}|jj j }| d r|jj d }t|tr|}||}z0t||jj }|||d||||jt|t||_t||kr|d WdSWdStyYdSw) al(ist) [first [,last] | .] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With . as argument, list 11 lines around the current line. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second argument is less than the first, it is a count. The current line in the current frame is indicated by "->". If an exception is being debugged, the line where the exception was originally raised or propagated is indicated by ">>", if it differs from the current line. r$NrrrrJ z\}}t|d} t| dkr+| d7} ||vr4| d7} n| d7} ||krA| d7} n||krI| d7} || d|qd S) zPrint a range of lines.rrrBz->z>> N) ryrBrrrrjustrrXr) r0rrrr[current_lineno exc_linenor r!srrrr~ s"   zPdb._print_linescCsz||}WnYdSd}z|jj}Wn tyYnw|r,|d|jdSz|j}Wn ty:Ynw|rG|d|jdS|jturY|d|j|j fdS|t|dS)z;whatis arg Print the type of the argument. Nz Method %sz Function %sz Class %s.%s) rqrrrrXr __class__typerr)r0rvaluer(rrr do_whatis s2     z Pdb.do_whatiscCsn|s|d|j|jiD] }|d|qdS||}||j|ji|<|d||fdS)zdisplay [expression] Display the value of the expression if it changed, each time execution stops in the current frame. Without expression, list all display expressions for the current frame. zCurrently displaying:z%s: %rzdisplay %s: %rN)rXr?rrarr setdefault)r0rr!rrrrr do_displayCs  zPdb.do_displaycCsT|r z |j|ji|=WdSty|d|YdSw|j|jddS)zundisplay [expression] Do not display the expression any more in the current frame. Without expression, clear all display expressions for the current frame. znot displaying %sN)r?rrarrrorrrr do_undisplayVs zPdb.do_undisplaycsfdd|j|jiDS)Ncrrr)rrTrrrrfs z*Pdb.complete_undisplay..)r?rrarrrrcomplete_undisplayeszPdb.complete_undisplaycCs$i|jj|j}tjd|ddS)zinteract Start an interactive interpreter whose global namespace contains all the (global and local) names found in the current scope. z *interactive*)localN)rarrir(interact)r0rrrrr do_interactiszPdb.do_interactcCs|}t|dkr$t|j}|D]}|d||j|fqdS|d|jvrCt|dkrC|d|d|j|dfdSd|dd|j|d<dS)acalias [name [command [parameter parameter ...] ]] Create an alias called 'name' that executes 'command'. The command must *not* be enclosed in quotes. Replaceable parameters can be indicated by %1, %2, and so on, while %* is replaced by all the parameters. If no command is given, the current alias for name is shown. If no name is given, all aliases are listed. Aliases may be nested and can contain anything that can be legally typed at the pdb prompt. Note! You *can* override internal pdb commands with aliases! Those internal commands are then hidden until the alias is removed. Aliasing is recursively applied to the first word of the command line; all other words in the line are left alone. As an example, here are two useful aliases (especially when placed in the .pdbrc file): # Print instance variables (usage "pi classInst") alias pi for k in %1.__dict__.keys(): print("%1.",k,"=",%1.__dict__[k]) # Print instance variables in self alias ps pi self rz%s = %sNrr)rrsortedr>rrXr)r0rrrrrrrdo_aliasrs $ z Pdb.do_aliascCs:|}t|dkr dS|d|jvr|j|d=dSdS)z9unalias name Delete the specified alias. rN)rrr>)r0rrrrr do_unaliass zPdb.do_unaliascsfdd|jDS)Ncrrr)rarrrrrz(Pdb.complete_unalias..)r>rrrrcomplete_unaliasrzPdb.complete_unalias)rYrMrPrWrbrZcCs2z|jD]}||qWdStyYdSwr.)r_rrW)r0 frame_linenorrrr@s   zPdb.print_stack_tracecCs6|\}}||jur d}nd}|||||dS)Nz> z )rarXformat_stack_entry)r0r prompt_prefixr[r rrrrrs   zPdb.print_stack_entrycCs|s tj||Szz t|d|}|WWSty&t|d|}YnwWnty9|d|YdSwtjjdkrI|d|dS|j durW|d|dS| |j dS)zh(elp) Without argument, print the list of available commands. With a command name as argument, print help about that command. "help pdb" shows the full pdb documentation. "help exec" gives help on the ! command. help_rzNo help for %rrzJNo help for %r; please do not run Python with -OO if you need command helpNz&No help for %r; __doc__ string missing) r8r9do_helpr}rrr:flagsoptimizerrXr)r0rtopiccommandrrrrs,     z Pdb.do_helpcCs||jjpddS)a(!) statement Execute the (one-line) statement in the context of the current stack frame. The exclamation point can be omitted unless the first word of the statement resembles a debugger command. To assign to a global variable you must always prefix the command with a 'global' command, e.g.: (Pdb) global list_options; list_options = ['-l'] (Pdb) r4N)rX help_execrrpr/rrrrs z Pdb.help_execcCs tdSr.)rr/rrrhelp_pdbs z Pdb.help_pdbcCstj|rtj|r|Stjtjd|}tj|r(|||jkr(|Stj|\}}|dkr8|d}tj|r@|StjD]$}tj |rVt |}tj |sKtj||}tj|rg|SqCdS)zHelper function for break/clear parsing -- may be overridden. lookupmodule() translates (possibly incomplete) file or module name into an absolute file name. rr4rN) rIrJisabsexistsrr:rwr@splitextislinkreadlink)r0rrkrootextdirnamefullnamerrrrs&      zPdb.lookupmodulec Csrd|_d|_ddl}||\}}}||j|_ddl}|j |j d|j|j |j |t d||dS)NTFr__main__)rrz __package__ __loader____spec__ __builtins__)rAr`runpy_get_module_detailsrwrxr@r__dict__rbupdateparentloaderrr )r0 module_namermod_namemod_specr(rrrr _runmodules  zPdb._runmodulecCsddl}|j|jd|tdd|_|||_d|_t |}d| |jf}Wdn1s8wY| |dS)Nrr)rrzrTFzexec(compile(%r, %r, 'exec'))) rrrbrrrArwr@r`io open_codereadr )r0rrr statementrrr _runscripts    zPdb._runscript)r2NNNFT)rr.)rN)yrrrrr7r\r]r^rmrjrvr{rzrrrrrtrrrrqrrXrrrrrcomplete_commandsrr do_bcomplete_break complete_brcomplete_tbreakr r r)complete_enabler+complete_disabler.complete_conditionr2complete_ignorer>do_clcomplete_clear complete_clrAdo_wdo_btrBrGdo_urIdo_drLdo_untrMdo_srPdo_nrU do_restartrWdo_rrYdo_cdo_contrZdo_jr_complete_debugrbdo_qdo_exitrcrodo_arpdo_rvrqrrrsrtrwcomplete_print complete_p complete_pprdo_lrdo_llrcomplete_sourcer~rcomplete_whatisrcomplete_displayrrrrrrrr@ line_prefixrrdo_hrrrrrrrrrr s /     M ]!!.    7  ! #     r )"rwheredownupbreaktbreakrbr*r'r/ conditionrMstepruntiljumpreturnretvalr continuer$longlistrr^ppwhatissourcedisplay undisplayrrunaliasdebugquitrz cCst|||dSr.)r r rrrrrrr Frr cCst|||Sr.)r r ) expressionrrrrrr Isr cCst|||dSr.)r rrrrr Lsr cOstj|i|Sr.)r r)rkwdsrrrrPrr)headercCs,t}|dur |||tjdSr.)r rXrr: _getframef_back)rpdbrrrrSs rcCsB|dur td}|durtdt}||d|dS)NrzAA valid traceback must be passed if no exception is being handled)r:rrr r]rt)tr^rrrr[s rcCsttjdSr.)rr:last_tracebackrrrrr isr zimport x; x.main()cCs ttdSr.)r TESTCMDrrrrtestqs rcCsddl}|tdSr#)pydocpagerr)rrrrrusrausage: pdb.py [-c command] ... [-m module | pyfile] [arg] ... Debug the Python program given by pyfile. Alternatively, an executable module or package to debug can be specified using the -m switch. Initial commands are read from .pdbrc files in your home directory and in the current directory, if they exist. Commands supplied with -c are executed after commands from .pdbrc files. To let the script run until an exception occurs, use "-c continue". To let the script run up to a given line X in the debugged file, use "-c 'until X'".c CsDddl}|tjdddddg\}}|stttdg}d}|D]!\}}|dvr6tttq%|d vr@||q%|d vrFd }q%|d}|s^tj |s^td |d td|r~ddl }z| |Wnt y}t tdYnw|tjdd<|stj|}tj|tjd<t} | j| z|r| |n| || jrWdStdWngtytd|dtddtjddYnKtytdddttdYn5tyt tdYn$t tdtdtd} | d| td|dYq)Nrrzmhc:rzcommand=rF)z-hz--help)z-cz --command)z-mTzError:zdoes not existz*The program finished and will be restarted Restartingzwith arguments:rrz/The program exited via sys.exit(). Exit status:)rz2Uncaught exception. Entering post mortem debuggingz1Running 'cont' or 'step' will restart the programz#Post mortem debugger finished. The z will be restarted)getoptr:rRr_usageexitrrIrJrrrrr print_excrealpathrr rHrLrrr`rr SystemExitr SyntaxErrorrt) roptsrrM run_as_moduleoptoptargr@rr r rrrmainsz                     rr)NNr.).rrIrrr:r8r5r%r(rrurrgrrr#rr__all__r"r,rr-rr6r9r _help_order_commandr}rprr r r rrrr r rrrrrr rrrrspC   =    L