[issue20853] pdb "args" crashes when an arg is not printable
Jurjen N.E. Bos
report at bugs.python.org
Mon Mar 17 09:38:51 CET 2014
Jurjen N.E. Bos added the comment:
I did figure it out.
It almost works, except when a argument lost its value, and the same name exists in the global context.
To be more specific: I simplified do_args to the following code
(that obviously ugly by explicitly evaluating repr in context, but
that is not the point)
def do_args(self, arg):
"""a(rgs)
Print the argument list of the current function.
Modified by Jurjen
"""
co = self.curframe.f_code
n = co.co_argcount
if co.co_flags & 4: n = n+1
if co.co_flags & 8: n = n+1
for i in range(n):
name = co.co_varnames[i]
expr = 'repr(%s)' % (name,)
self.message('%s = %s' % (name, self._getval_except(expr)))
At it works perfectly, except for this little surprise:
>>> bar = "BAR"
>>> def foo(bar):
... del bar
... return 5
>>> pdb.runcall(f, 10)
> <stdin>(2)f()
-> del bar
(Pdb) a
bar = 5
(Pdb) n
> <stdin>(3)f()
-> return 5
(Pdb) a
bar = 'BAR' ##### Huh? Expected undefined
I'll leave it to the experts to patch this in proper Python coding style.
So, the conclusion is we need a way to safely evaluate the call to repr() in context, with self.curframe_locals[co.co_varnames[i]] as argument.
I did not find a good supporting routine for that elsewhere in pdb.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20853>
_______________________________________
More information about the Python-bugs-list
mailing list