3 \~"@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z GdddeZddddd d d d d g ZddZddZddZGdddeZdZGdddejejZedk rbd ddddddddd d!d"d#d$d%d&d'd(dd)d*d+d,d-d.d/d0d1d2d3d4d5d6d7g"Zx*eD]"Zeeed8ejjd97Zq,Weejj7Z[[dId:dZdJd;dZ dd Z#dKd?d Z$d@dZ%dAZ&dBdCZ'dDd Z(dEZ)dFdGZ*e+dHkrddl,Z,e,j*dS)La 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/lib64/python3.6/pdb.pyrUsrrunpmPdbrunevalrunctxruncall set_trace post_mortemhelpcCsxtjdtj|}y t|}Wntk r4dSX|4x,t|ddD]\}}|j|rJ|||fSqJWWdQRXdS)Nzdef\s+%s\s*[(])start)recompileescapeopenOSError enumeratematch)funcnamefilenameZcrefplinenolinerrr find_function\s  r cCsXtj|\}}tj|r,|j|jkr,|dfStj|r>|dfStj||d|dfS)Nr)inspectZ findsourceZisframe f_globalsf_localsZismoduleZgetblock)objlinesrrrrgetsourcelinesis  r&cCs8ttj|}|jx|D]\}}||kr|SqWdS)Nr)listdisZfindlinestartsreverse)codeZlastiZ linestartsirrrr lasti2linenors r,c@seZdZdZddZdS)_rstrz#String that doesn't quote its repr.cCs|S)Nr)selfrrr__repr__}sz_rstr.__repr__N)rrrrr/rrrrr-{sr-z -> c@seZdZdZdddZddZd 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`daZHeHZIdbdcZJeZKdddeZLeLZMeLZNdfdgZOdhdiZPePZQdjdkZReRZSdldmZTddndoZUdpdqZVdrdsZWeZXeZYeZZdtduZ[e[Z\dvdwZ]e]Z^dxdyZ_eZ`fdfdzd{Zad|d}ZbeZcd~dZdeZeddZfddZgddZhddZiddZjddZkddddddgZlddZmenfddZoddZpepZqddZrddZsddZtddZudS)r NtabFTc $CsJtjj||dtjj|||||r,d|_d|_i|_i|_d|_ d|_ i|_ yddl }|j dWntk rzYnXd|_||_g|_|r(dtjkrtjd}y.ttjj|d} |jj| WdQRXWntk rYnXy$td} |jj| WdQRXWntk r&YnXi|_i|_i|_d|_d|_dS) N)skiprz(Pdb) Fz `@#$%^&*()=+[{]}\|;:'",<>?HOMEz.pdbrc)bdbBdb__init__cmdCmdZ use_rawinputpromptaliases displaying mainpyfile_wait_for_mainpyfile tb_linenoreadlineZset_completer_delims ImportError allow_kbdintnosigintrcLinesosenvironrpathjoinextendrcommandscommands_dopromptcommands_silentcommands_defining commands_bnum) r. completekeystdinstdoutr1rBZreadrcr?ZenvHomeZrcFilerrrr6sH   z Pdb.__init__cCs*|jr t|jd|j|j|dS)Nz- Program interrupted. (Use 'cont' to resume).)rAKeyboardInterruptmessageset_stepr)r.Zsignumframerrrsigint_handlers  zPdb.sigint_handlercCstjj||jdS)N)r4r5resetforget)r.rrrrVs z Pdb.resetcCs&d|_g|_d|_d|_|jjdS)Nr)rstackcurindexcurframer>clear)r.rrrrWs z Pdb.forgetcCsl|j|j||\|_|_x*|rFt|jj|j}||j|j<|j }qW|j|jd|_ |j j |_ |j S)Nr)rWZ get_stackrXrYr,tb_framef_codetb_lastir>tb_nextrZr#curframe_locals execRcLines)r.ftbrrrrsetups   z Pdb.setupcCsh|js dS|j}|jg|_xD|rb|jj}|r |ddkr |j|r |jt|7_dSq WdS)Nr#T)rCr)popstriponecmdreversed)r.rCrrrrras  zPdb.execRcLinescCs.|jr dS|j|r*|jd|j|ddS)znThis method is called when there is the remote possibility that we ever need to stop in this function.Nz--Call--)r=Z stop_hererR interaction)r.rTZ argument_listrrr user_calls   z Pdb.user_callcCsH|jr.|j|j|jjks$|jdkr(dSd|_|j|rD|j|ddS)z;This function is called when we stop or break at this line.rNF)r=r<canonicr] co_filenamef_lineno bp_commandsrj)r.rTrrr user_lines  z Pdb.user_linecCst|ddr|j|jkr|j}d|_|j}|j|dx|j|D]}|j|qBW||_|j|sv|j|j|j |j |r|j |j 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) getattrrqrIlastcmdrdrhrKprint_stack_entryrXrYrJ_cmdlooprW)r.rTrqZ lastcmd_backrrrrros      zPdb.bp_commandscCs.|jr dS||jd<|jd|j|ddS)z7This function is called when a return trap is set here.N __return__z --Return--)r=r#rRrj)r.rTZ return_valuerrr user_returns   zPdb.user_returncCsj|jr dS|\}}}||f|jd<| r4|tkr4dnd}|jd|tj||djf|j||dS)zoThis function is called if an exception occurs, but only if we are to stop at or just below this level.NZ __exception__z Internal r2z%s%sr)r=r# StopIterationrR tracebackformat_exception_onlyrgrj)r.rTexc_infoexc_type exc_value exc_tracebackprefixrrruser_exception's zPdb.user_exceptionc CsDx>yd|_|jd|_PWqtk r:|jdYqXqWdS)NTFz--KeyboardInterrupt--)rAcmdlooprQrR)r.rrrru;sz Pdb._cmdloopcCsb|jj|j}|r^xJ|jD]>\}}|j|}||k r||kr|||<|jd|||fqWdS)Nzdisplay %s: %r [old: %r])r;getrZitems_getval_exceptrR)r.r;exprZoldvalueZnewvaluerrrpreloopHs z Pdb.preloopcCsZtjrtjtjtjdt_|j||r4|jdS|j|j|j|j |jdS)N) r _previous_sigint_handlersignalSIGINTrdrWrtrXrYru)r.rTrzrrrrjUs zPdb.interactioncCs|dk r|jt|dS)z{Custom displayhook for the exec in default(), which prevents assignment of the _ variable in the builtins. N)rRrepr)r.r$rrr displayhookcszPdb.displayhookc Cs|dddkr|dd}|j}|jj}ydt|ddd}tj}tj}tj}z(|jt_|jt_|jt_t|||Wd|t_|t_|t_XWn4tj dd}|j t j |dj YnXdS)Nr! zZsinglerx)r`rZr"rsysrPrOrexecr|errorrzr{rg) r.rlocalsglobalsr*Z save_stdoutZ save_stdinZsave_displayhookr|rrrdefaultks(  z Pdb.defaultcCs|js |S|j}xx|d|jkr|j|d}d}x0|ddD] }|jdt||}|d7}qDW|jddj|dd}|j}qW|ddkr|jd}|dkr||d dj}|jj ||d|j }|S) z*Handle alias expansion and ';;' separator.rrN%z%* aliasz;;r) rgsplitr:replacestrrGfindlstripcmdqueueappendrstrip)r.rargsZiiZtmpArgZmarkernextrrrprecmds&     z Pdb.precmdcCs"|jstjj||S|j|SdS)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. N)rLr7r8rhhandle_command_def)r.rrrrrhsz Pdb.onecmdc Cs|j|\}}}|sdS|dkr0d|j|j<dS|dkrBg|_dS|j|j}|rf|j|d|n |j|yt|d|}Wntk r|j}YnX|j |j krd|j |j<g|_dSdS) z8Handles one command line during command list definition.NZsilentTendrrdo_F) Z parselinerKrMrrIrrrAttributeErrorrrcommands_resumingrJ)r.rr7argZcmdlistfuncrrrrs,      zPdb.handle_command_defcCst||jddS)N)file)printrP)r.msgrrrrRsz Pdb.messagecCstd||jddS)Nz***)r)rrP)r.rrrrrsz Pdb.errorc Cs|jjdrgSy|j||||}Wntk r>g}YnXtj|d}xP|D]H}tjj|rt|j|dqTtjj |rT|j jdrT|j|dqTW|S) N:,*/.py.pyw)rr)rr) rgendswith_complete_expression ExceptionglobrDrFisdirrisfilelower)r.textrbegidxendidxZretglobsfnrrr_complete_locations   zPdb._complete_locationcsfddttjjDS)Ncs.g|]&\}}|dk rt|jrt|qS)N)r startswith).0r+bp)rrr sz*Pdb._complete_bpnumber..)rr4 Breakpoint bpbynumber)r.rrrrr)rr_complete_bpnumberszPdb._complete_bpnumberc s|js gS|jjj}|j|jdkrjdy0|d}xddD]}t||}qPWWnttfk r|gSXdj dddfddt |DSfdd|j DSdS) N.rrcs"g|]}|jdr|qS)rrx)r)rn)dottedrrrrsz,Pdb._complete_expression..csg|]}|jr|qSr)r)rr)rrrrsrxrx) rZr"copyupdater`rrrKeyErrorrrGdirkeys)r.rrrrnsr$partr)rrrrrs    zPdb._complete_expressioncCs(|sttjjd}n"y t|}Wn|jddS||_||jkrf|j||j||j |f}nd}g|j|<d|j|<d|j |<|j }d|_ d|_ zzy |j Wnht k r|r|d|j|<|d|j|<|d|j |<n|j|=|j|=|j |=|jd YnXWdd|_ ||_ XdS) 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)lenr4rrintrrMrIrJrKr9rLrrQ)r.rZbnumZold_command_defsZ prompt_backrrr do_commandss@%       zPdb.do_commandsrcCs@|s<|jr8|jdx"tjjD]}|r|j|jqWdSd}d}d}|jd}|dkr~||ddj}|d|j}|j d}d} |dkr|d|j}|j |} | s|j d|dS| }||ddj}y t |}Wn$t k r|j d|dSXny t |}Wnt k ryt||jj|j} Wn|} YnXy.t| d rl| j} | j} | j} | j}| j}Wn@|j|\} }}| s|j d |dS| } t |}YnXYnX|s|j}|j||}|r<|j||||| }|r|j |n*|j||d }|jd |j|j|jfdS) 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.zBreakpoint %d at %s:%drx) breaksrRr4rrZbpformatrrrrfind lookupmodulerr ValueErrorevalrZr"r`hasattrr__code__co_nameco_firstlinenormlineinfo defaultFile checklineZ set_break get_breaksnumberrr)r.rZ temporaryrrrcondZcommaZcolonrrbrr*oklnrerrrrrdo_breakTs~             z Pdb.do_breakcCs"|jjj}|dkr|jr|j}|S)zProduce a reasonable default.z)rZr]rmr<)r.rrrrrs zPdb.defaultFilecCs|j|ddS)ztbreak [ ([filename:]lineno | function) [, condition] ] Same arguments as break, but sets a temporary breakpoint: it is automatically deleted when first hit. rN)r)r.rrrr do_tbreaksz Pdb.do_tbreakc Csd}|jd}t|dkr(|dj}nt|dkrB|dj}n|S|dkrR|S|jd}|ddkr~|d=t|dkr~|S|j}t|dkr|d}n|j|d}|r|}|d}t||} | p|S) N'rrr2rr.)NNN)rrrgrrr ) r.Z identifierZfailedZidstringidpartsZfnameitemrbZanswerrrrrs.         z Pdb.lineinfocCst|dr|jjnd}tj|||}|s6|jddS|j}| sp|ddksp|dddksp|dddkr~|jd 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. rZNz End of filerrerz"""z'''zBlank or comment)rrZr" linecachegetlinerRrgr)r.rrrrrrrrs   z Pdb.checklinecCsl|j}x^|D]V}y|j|}Wn,tk rL}z|j|WYdd}~XqX|j|jd|qWdS)zenable bpnumber [bpnumber ...] Enables the breakpoints given as a space separated list of breakpoint numbers. Nz Enabled %s)rget_bpbynumberrrenablerR)r.rrr+rrrrr do_enables z Pdb.do_enablecCsl|j}x^|D]V}y|j|}Wn,tk rL}z|j|WYdd}~XqX|j|jd|qWdS)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)rrrrdisablerR)r.rrr+rrrrr do_disable s zPdb.do_disablecCs|jdd}y |d}Wntk r0d}YnXy|j|dj}WnHtk rf|jdYnXtk r}z|j|WYdd}~Xn.X||_|s|jd|jn|jd|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. rrNrzBreakpoint number expectedz#Breakpoint %d is now unconditional.z$New condition set for breakpoint %d.) r IndexErrorrrgrrrrRr)r.rrrrrrrr do_condition!s   zPdb.do_conditioncCs|j}yt|dj}Wnd}YnXy|j|dj}WnHtk rb|jdYnvtk r}z|j|WYdd}~XnLX||_|dkr|dkrd|}nd}|jd||j fn|jd|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. rrzBreakpoint number expectedNz %d crossingsz 1 crossingz%Will ignore next %s of breakpoint %d.z-Will stop next time breakpoint %d is reached.) rrrgrrrrignorerRr)r.rrcountrrZcountstrrrr do_ignore<s(   z Pdb.do_ignorec !Cs|sxy td}Wntk r(d}YnX|jj}|d krtddtjjD}|jx|D]}|jd|q^WdSd |kr|j d }|d|}||d d}y t |}Wnt k rd |}YnX|j ||}|j ||}|r|j|nx|D]}|jd|qWdS|j} xd| D]\}y|j|}Wn.t k rl}z|j|WYdd}~XnX|j||jd|q,WdS) 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? noyyescSsg|] }|r|qSrr)rrrrrrmsz Pdb.do_clear..z Deleted %sNrrzInvalid line number (%s))rr)inputEOFErrorrgrr4rrZclear_all_breaksrRrrrrZ clear_breakrrrZclear_bpbynumber) r.rZreplyZbplistrr+rrrZ numberlistrrrdo_clear_sF              z Pdb.do_clearcCs |jdS)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_trace)r.rrrrdo_wheresz Pdb.do_wherecCs>||_|j|jd|_|jj|_|j|j|jd|_dS)Nr)rYrXrZr#r`rtr)r.rrrr _select_frames  zPdb._select_framec Csx|jdkr|jddSyt|p"d}Wn"tk rJ|jd|dSX|dkrZd}ntd|j|}|j|dS)zu(p) [count] Move the current frame count (default one) levels up in the stack trace (to an older frame). rz Oldest frameNrzInvalid frame count (%s))rYrrrmaxr)r.rrnewframerrrdo_ups  z Pdb.do_upc Cs|jdt|jkr"|jddSyt|p,d}Wn"tk rT|jd|dSX|dkrnt|jd}ntt|jd|j|}|j|dS)zd(own) [count] Move the current frame count (default one) levels down in the stack trace (to a newer frame). rz Newest frameNzInvalid frame count (%s)r)rYrrXrrrminr)r.rrrrrrdo_downs z Pdb.do_downc Csf|rPy t|}Wn"tk r2|jd|dSX||jjkrT|jddSnd}|j|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. zError in argument: %rNz7"until" line number is smaller than current line numberr)rrrrZrnZ set_until)r.rrrrrdo_untils   z Pdb.do_untilcCs |jdS)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)rS)r.rrrrdo_stepsz Pdb.do_stepcCs|j|jdS)zxn(ext) Continue execution until the next line in the current function is reached or it returns. r)Zset_nextrZ)r.rrrrdo_nexts z Pdb.do_nextcCs<|r4ddl}tjdd}|j|t_|tjdd<tdS)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". rNr)shlexrargvrr)r.rr Zargv0rrrdo_runs  z Pdb.do_runcCs|j|jdS)zPr(eturn) Continue execution until the current function returns. r)Z set_returnrZ)r.rrrr do_returns z Pdb.do_returnc Cs>|js2ytjtj|jt_Wntk r0YnX|jdS)z]c(ont(inue)) Continue execution, only stop when a breakpoint is encountered. r)rBrrrUr rrZ set_continue)r.rrrr do_continueszPdb.do_continuecCs|jdt|jkr"|jddSy t|}Wntk rL|jdYnnXy:||j_|j|jd|f|j|j<|j|j|jWn0tk r}z|jd|WYdd}~XnXdS)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) rYrrXrrrrZrnrt)r.rerrrdo_jump"s   z Pdb.do_jumpcCsztjd|jj}|j}t|j|j|j}d|j j |_ |j dtj |j |||f|j dtj|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)rsettracerZr"r`r rNrOrPr9rgrR call_tracingr Ztrace_dispatchrs)r.rrrprrrdo_debug?s    z Pdb.do_debugcCsd|_|jdS)z[q(uit) exit Quit from the debugger. The program being executed is aborted. Tr)_user_requested_quitset_quit)r.rrrrdo_quitRsz Pdb.do_quitcCs|jdd|_|jdS)z=EOF Handles the receipt of EOF as a command. r2Tr)rRrr)r.rrrrdo_EOF]s z Pdb.do_EOFcCs|jj}|j}|j}|jd@r&|d}|jd@r8|d}xJt|D]>}|j|}||krp|jd|||fqB|jd|fqBWdS)zHa(rgs) Print the argument list of the current function. rz%s = %rz%s = *** undefined ***N)rZr]r` co_argcountco_flagsrange co_varnamesrR)r.rcodictrr+namerrrdo_argsfs   z Pdb.do_argscCs.d|jkr |jt|jdn |jddS)zQretval Print the return value for the last return of a function. rvzNot yet returned!N)r`rRrr)r.rrrr do_retvalws z Pdb.do_retvalc CsNyt||jj|jStjdd}|jtj|dj YnXdS)Nrrrx) rrZr"r`rr|rrzr{rg)r.rr|rrr_getvals z Pdb._getvalc Cshy.|dkrt||jj|jSt||j|jSWn4tjdd}tj|dj }t d|SdS)Nrrz** raised %s **rx) rrZr"r`r#rr|rzr{rgr-)r.rrTr|rrrrrszPdb._getval_exceptc Cs*y|jt|j|Wn YnXdS)z@p expression Print the value of the expression. N)rRrr&)r.rrrrdo_pszPdb.do_pc Cs,y|jtj|j|Wn YnXdS)zHpp expression Pretty-print the value of the expression. N)rRpprintZpformatr&)r.rrrrdo_ppsz Pdb.do_ppcCsdd|_d}|r|dkry^d|krX|jd\}}t|j}t|j}||krr||}nt|j}td|d}Wqtk r|jd|dSXn0|jdks|dkrtd|jj d}n |jd}|dkr|d}|jj j }|j |}yZt j||jj}|j||d||||jt|t||_t||krF|jd Wntk r^YnXdS) 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'NrrrzError in argument: %r z[EOF])rsrrrgrrrrrZrnr]rmget_file_breaksrgetlinesr" _print_linesrrrRrQ)r.rZlastfirstr breaklistr%rrrdo_lists>        z Pdb.do_listcCsh|jjj}|j|}yt|j\}}Wn*tk rP}z|j|dSd}~XnX|j||||jdS)z\longlist | ll List the whole source code for the current function or frame. N)rZr]rmr,r&rrr.)r.rrr0r%rrrrr do_longlists   zPdb.do_longlistcCsjy|j|}Wn dSyt|\}}Wn.ttfk rX}z|j|dSd}~XnX|j||dS)z^source expression Try to get source code for the given object and display it. N)r&r&r TypeErrorrr.)r.rr$r%rrrrr do_sources z Pdb.do_sourcec Cs|r|j}|jj|d }nd }}xt||D]|\}}t|jd} t| dkrX| d7} ||krj| d7} n| d7} ||kr| d7} n||kr| d7} |j| d|jq.Wd S) zPrint a range of lines.rrrrBz->z>> Nrxrx) rnr>rrrrjustrrRr) r.r%rrrTZcurrent_linenoZ exc_linenorrsrrrr.s    zPdb._print_linescCsy|j|}Wn dSd}y |j}Wntk r<YnX|rV|jd|jdSy |jj}Wntk rvYnX|r|jd|jdS|jtkr|jd|j|j fdS|jt|dS)z;whatis arg Print the type of the argument. Nz Function %sz Method %sz Class %s.%s) r&rrrRrr __class__typerr)r.rvaluer*rrr do_whatiss.   z Pdb.do_whatiscCsp|s<|jdx\|jj|jijD]}|jd|q$Wn0|j|}||jj|ji|<|jd||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)rRr;rrZrr setdefault)r.rrvalrrr do_display4s  zPdb.do_displayc CsT|r@y|jj|ji|=WqPtk r<|jd|YqPXn|jj|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;rrZrrrf)r.rrrr do_undisplayGs zPdb.do_undisplaycsfdd|jj|jiDS)Ncsg|]}|jr|qSr)r)rr)rrrrWsz*Pdb.complete_undisplay..)r;rrZ)r.rrrrr)rrcomplete_undisplayVszPdb.complete_undisplaycCs*|jjj}|j|jtjd|ddS)zinteract Start an interactive interpreter whose global namespace contains all the (global and local) names found in the current scope. z *interactive*)ZlocalN)rZr"rrr`r*interact)r.rrrrr do_interactZs  zPdb.do_interactcCs|j}t|dkrLt|jj}x$|D]}|jd||j|fq(WdS|d|jkrt|dkr|jd|d|j|dfndj|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:rrRrG)r.rrrrrrrdo_aliasds  "z Pdb.do_aliascCs6|j}t|dkrdS|d|jkr2|j|d=dS)z9unalias name Delete the specified alias. rN)rrr:)r.rrrrr do_unaliass  zPdb.do_unaliascsfdd|jDS)Ncsg|]}|jr|qSr)r)ra)rrrrsz(Pdb.complete_unalias..)r:)r.rrrrr)rrcomplete_unaliasszPdb.complete_unaliasrr r rrrc Cs8yx|jD]}|j|q WWntk r2YnXdS)N)rXrtrQ)r. frame_linenorrrrs  zPdb.print_stack_tracecCs6|\}}||jkrd}nd}|j||j||dS)Nz> z )rZrRZformat_stack_entry)r.rIZ prompt_prefixrTrrrrrrts  zPdb.print_stack_entrycCs|stjj||Sy}xtjj |rtj |}qWtjj||}tjj|r|SqWdS)zHelper function for break/clear parsing -- may be overridden. lookupmodule() translates (possibly incomplete) file or module name into an absolute file name. rr2z.pyN) rDrFisabsexistsrGrrlr<splitextislinkreadlink)r.rrbrootZextdirnamefullnamerrrrs"   zPdb.lookupmodulec Cstddl}|jj|jjd|tdd|_|j||_d|_t |d}d|j |jf}WdQRX|j |dS)Nr__main__)r__file__ __builtins__TFrbzexec(compile(%r, %r, 'exec'))) rW__dict__r[rrYr=rlr<rrreadr )r.rrWr statementrrr _runscripts    zPdb._runscript)r0NNNFT)r)N)vrrrrr6rUrVrWrdrarkrprorwrrurrjrrrrhrrRrrrrrZcomplete_commandsrrZdo_bZcomplete_breakZ complete_brZcomplete_tbreakrrrZcomplete_enablerZcomplete_disablerZcomplete_conditionrZcomplete_ignorerZdo_clZcomplete_clearZ complete_clrZdo_wZdo_btrrZdo_urZdo_dr Zdo_untr Zdo_sr Zdo_nrZ do_restartrZdo_rrZdo_cZdo_contrZdo_jrZcomplete_debugrZdo_qZdo_exitrr$Zdo_ar%Zdo_rvr&rr'r)Zcomplete_printZ complete_pZ complete_ppr1Zdo_lr2Zdo_llr4Zcomplete_sourcer.r<Zcomplete_whatisr?Zcomplete_displayr@rArCrErFrHrr line_prefixrtrJZdo_hrMrNrr^rrrrr s /     M ]!!.    1 ! #    whereZdownZupbreakZtbreakr[rrrZ conditionrIsteprZuntilZjumpreturnZretvalcontinuer'ZlonglistrrZppZwhatissourceZdisplayZ undisplayrBrZunaliasdebugquitrz cCstj|||dS)N)r r )r]rrrrrr #scCstj|||S)N)r r )Z expressionrrrrrr &scCst|||dS)N)r )r]rrrrrr )scOstj||S)N)r r)rkwdsrrrr-scCstjtjjdS)N)r rr _getframef_backrrrrr0scCsB|dkrtjd}|dkr$tdt}|j|jd|dS)NrzAA valid traceback must be passed if no exception is being handled)rr|rr rVrj)trrrrr5s cCsttjdS)N)rrlast_tracebackrrrrr Cszimport x; x.main()cCs ttdS)N)r TESTCMDrrrrtestKsrncCsddl}|jtdS)Nr)pydocZpagerr)rorrrrOsausage: pdb.py [-c command] ... pyfile [arg] ... Debug the Python program given by pyfile. 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 Csddl}|jtjdddddg\}}|s>tttjdg}x<|D]4\}}|dkrjtttjqH|dkrH|j|qHW|d}tjj |std |d tjd|tjdd<tjj |tjd<t }|j j |xy|j||jrPtd Wqtk r0td |dtddj|Yqtk r`tdddttjdYqtk rtjtjdYqtjtdtdtjd}|jd|td|dYqXqWdS)Nrrzhc:--helpz --command=r-h-c --commandzError:zdoes not existz*The program finished and will be restartedZ Restartingzwith arguments:r6rz/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)rqrp)rrrs)getoptrr r_usageexitrrDrFrPrUr rCrHr^rrrG SystemExitr| SyntaxErrorrz print_excrj) rtZoptsrrIoptZoptargr<pdbrkrrrmain`sV             r|rW)NN)NN)N)-rrDrrr7r4r(r*rr(rr!rzrrr__all__r r&r,rr-r_r5r8r Z _help_orderZ_commandrrrgrMr r r rrrr rmrnrrur|rr{rrrrBst      "    <