Wednesday 15 June 2011

debugging - Python's debugger's step-through and free-running modes follow different execution paths -



debugging - Python's debugger's step-through and free-running modes follow different execution paths -

if run script

import sys if sys.gettrace(): print 'ok' else: assert false, 'good grief'

...like this

% python -mpdb bugdemo.py

...(python v. 2.7.8) first see prompt this:

-> import sys (pdb)

if @ point, repeatedly come in s step through script, see this:

> <path-to-script>/bugdemo.py(2)<module>() -> if sys.gettrace(): (pdb) s > <path-to-script>/bugdemo.py(3)<module>() -> print "ok" (pdb) s ok --return-- > <path-to-script>/bugdemo.py(3)<module>()->none -> print "ok" (pdb)

but, if instead of stepping through code, @ first debugger prompt come in c (short cont, i.e. continue), the code's execution follows different path:

% python -mpdb bugdemo.py > <path-to-script>/bugdemo.py(1)<module>() -> import sys (pdb) c traceback (most recent phone call last): file "/users/yt/library/frameworks/python.framework/versions/2.7/lib/python2.7/pdb.py", line 1314, in main pdb._runscript(mainpyfile) file "/users/yt/library/frameworks/python.framework/versions/2.7/lib/python2.7/pdb.py", line 1233, in _runscript self.run(statement) file "/users/yt/library/frameworks/python.framework/versions/2.7/lib/python2.7/bdb.py", line 387, in run exec cmd in globals, locals file "<string>", line 1, in <module> file "bugdemo.py", line 1, in <module> import sys assertionerror: grief uncaught exception. entering post mortem debugging running 'cont' or 'step' restart programme > <path-to-script>/bugdemo.py(1)<module>() -> import sys (pdb)

does know what's going on here? bug1 should report? or there way rationalize it?

1if bug, a whopper of bug: debugger follows different execution paths in step-through , free-run worse useless.

lib\bdb.py:227

def set_continue(self): # don't stop except @ breakpoints or when finished self._set_stopinfo(self.botframe, none, -1) if not self.breaks: # no breakpoints; run without debugger overhead sys.settrace(none) frame = sys._getframe().f_back while frame , frame not self.botframe: del frame.f_trace frame = frame.f_back

i.e. pdb removes trace function in circumstances private business. seek outsmart checking presence , shoot in foot. congratulations on that.

python debugging

No comments:

Post a Comment