[ python-Bugs-1472251 ] pdb 'run' crashes when the it's first argument is non-string
SourceForge.net
noreply at sourceforge.net
Sun Jun 25 20:54:26 CEST 2006
Bugs item #1472251, was opened at 2006-04-18 05:16
Message generated for change (Comment added) made by isandler
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1472251&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 3
Submitted By: Kuba KoÅczyk (jakamkon)
Assigned to: Nobody/Anonymous (nobody)
Summary: pdb 'run' crashes when the it's first argument is non-string
Initial Comment:
Pdb 'run/runeval' commands fails to check the type of
given argument.When argument to 'run/runeval' is
non-string the functions crashes with further
impilications on (correctly)invoking this functions:
Python 2.5a1 (trunk:45527, Apr 18 2006, 11:12:31)
>>> def x(): pass
>>> import pdb
>>> pdb.run(x())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jkk/python/python-svn/Lib/pdb.py", line
1113, in run
Pdb().run(statement, globals, locals)
File "/home/jkk/python/python-svn/Lib/bdb.py", line
363, in run
cmd = cmd+'\n'
TypeError: unsupported operand type(s) for +:
'NoneType' and 'str'
>>> pdb.run('x()')
> /home/jkk/python/python-svn/Lib/pdb.py(1113)run()
-> Pdb().run(statement, globals, locals)
(Pdb)
# CTRL-D pressed
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jkk/python/python-svn/Lib/pdb.py", line
1113, in run
Pdb().run(statement, globals, locals)
File "/home/jkk/python/python-svn/Lib/pdb.py", line
1113, in run
Pdb().run(statement, globals, locals)
File "/home/jkk/python/python-svn/Lib/bdb.py", line
48, in trace_dispatch
return self.dispatch_line(frame)
File "/home/jkk/python/python-svn/Lib/bdb.py", line
67, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
The solution is to simply ensure that the first
argument passed to the 'run/runeval' functions is string.
----------------------------------------------------------------------
Comment By: Ilya Sandler (isandler)
Date: 2006-06-25 11:54
Message:
Logged In: YES
user_id=971153
I have looked at what's happening in a bit more detail and
now I agree that the current behaviour seems wrong.
Apparently, when one passes a nonstring to bdb's run(), bdb
sets tracing first and only then throws an exception...
Leaving tracing on seems like a bad thing to do
Would calling settrace() a couple lines later be the
simplest solution then?
so relevant fragment of bdb.py's run() becomes:
if not isinstance(cmd, types.CodeType):
cmd = cmd+'\n'
sys.settrace(self.trace_dispatch)
This should prevent bdb from turning tracing too early.
What do you think?
----------------------------------------------------------------------
Comment By: Kuba KoÅczyk (jakamkon)
Date: 2006-06-19 06:48
Message:
Logged In: YES
user_id=1491175
You're right,but don't you think that this kind of switching
between namespaces could confuse users?
----------------------------------------------------------------------
Comment By: Ilya Sandler (isandler)
Date: 2006-05-22 20:36
Message:
Logged In: YES
user_id=971153
Well, I don't see anything in bdb's run which could
overwrite your namespace..
What seems to be happenning in your example is that bdb's
first line event happens while bdb is still in run(), so you
when you see pdb's prompt, are in bdb's namespace not in
yours.. If you do "next" you will get where you should be..
bagira:~> python2.4
Python 2.4.1 (#2, May 5 2005, 11:32:06)
>>> def x(): print "in x"
>>> import pdb
>>> pdb.run( x())
in x
TypeError: unsupported operand type(s) for +: 'NoneType'
and 'str'
>>> pdb.run( 'x()' )
> /usr/lib/python2.4/pdb.py(987)run()
-> Pdb().run(statement, globals, locals)
(Pdb) n #now you are back in your namespace
> <string>(1)?()
(Pdb) p x #and you get your symbols back
<function x at 0x4021be2c>
(Pdb) p pdb
<module 'pdb' from '/usr/lib/python2.4/pdb.pyc'>
(Pdb) n
in x
--Return--
> <string>(1)?()->None
What do you think?
----------------------------------------------------------------------
Comment By: Kuba KoÅczyk (jakamkon)
Date: 2006-05-22 02:20
Message:
Logged In: YES
user_id=1491175
The point is that when you want to invoke pdb.run correctly
(with string argument) after getting TypeError as in above
example,
your namespace is probably overwritten or deleted so that
you don't have access to previously defined symbols.
>>> def x():pass
>>> import pdb
>>> pdb.run(x())
TypeError
>>> pdb.run('x()')
> /home/jkk/python-svn/Lib/pdb.py(1122)run()
-> Pdb().run(statement, globals, locals)
(Pdb) pdb
*** NameError: name 'pdb' is not defined
(Pdb) x
*** NameError: name 'x' is not defined
----------------------------------------------------------------------
Comment By: Ilya Sandler (isandler)
Date: 2006-05-21 16:25
Message:
Logged In: YES
user_id=971153
I would not classify your example as a crash. You passed a
wrong value (None in your case) into pdb.run() and got back
a TypeError...Isn't it an expected response?
E.g if you do: >>>max(13)
You'll also get: "TypeError"
Am I missing something? Could you clarify?
----------------------------------------------------------------------
Comment By: Kuba KoÅczyk (jakamkon)
Date: 2006-04-18 05:36
Message:
Logged In: YES
user_id=1491175
Patch is in #1472257
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1472251&group_id=5470
More information about the Python-bugs-list
mailing list