[Patches] [ python-Patches-1429539 ] pdb: fix for 1326406 (import __main__ pdb failure)

SourceForge.net noreply at sourceforge.net
Fri Apr 21 04:39:42 CEST 2006


Patches item #1429539, was opened at 2006-02-10 19:34
Message generated for change (Comment added) made by isandler
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1429539&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: Library (Lib)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Ilya Sandler (isandler)
Assigned to: Nobody/Anonymous (nobody)
Summary: pdb: fix for  1326406 (import  __main__ pdb failure)

Initial Comment:
The patch allows pdb to debug program which 
import from __main__


----------------------------------------------------------------------

>Comment By: Ilya Sandler (isandler)
Date: 2006-04-20 19:39

Message:
Logged In: YES 
user_id=971153

I do see your point (In fact it was me who submitted the
patch #896011 which separated pdb namespace from the
program's -- and thus broke imports from __main__ ;-))..

I do want to bring a couple of points:

1. I don't think it matters whether a program can
intentionally interfere with pdb...Even when pdb's namespace
is separated, it's easy for the program to  interfere with
debugger.. (Or delete your home directory for that matter)

2. Importing from __main_ may not be common in the std lib,
but that's simply because stdlib doesn't contain that many
executable hence there are very few places where there is
__main__ to import from. 

google search for "from __main__ import" results in about 1M
hits.


3. Just for the record, profile module does not separate its
 namespace from programs's either...

So, basically, it boils down to this: what's worse breaking
imports from __main__ or risking accidental interference
between pdb and the program (e.g if your program redefines a
help symbol)...

As a middle ground it might be a good idea to expand the
patch to reduce pdb's dependency on module global symbols
and thus reducing the risk of interference.

What do you think?




----------------------------------------------------------------------

Comment By: Kuba Kończyk (jakamkon)
Date: 2006-04-20 04:17

Message:
Logged In: YES 
user_id=1491175

I think that exposing pdb's namespaces for debugged code is
dangerous.When debugged code have this kind of access he can
dynamic change pdb's behaviour without your control:

y.py:
die = """\
def destroy(x,y):
        print 'Iam crashing your HOME and deleting your FILES'

Pdb.__dict__['do_break'] = destroy # pdb's break = destroy
"""
x.py:
# innocently looking code;)
import y
exec(y.puff)
print "X"

with your patch:
$ python2.5 -m pdb x.py
> /home/xyz/python/x.py(1)<module>()
-> import y
(Pdb) Pdb.__dict__['do_break']
<function do_break at 0xb7cafdf4>
(Pdb) break
(Pdb) n
> /home/xyz/python/x.py(2)<module>()
-> exec(y.puff)
(Pdb) n
> /home/xyz/python/x.py(3)<module>()
-> print "X"
(Pdb) Pdb.__dict__['do_break']
<function destroy at 0xb7cb81b4>
(Pdb) break
Iam crashing your HOME and deleting your FILES

I think that this patch can't be accepted due to above
reason.According to my advanced reaserch;) ( find Lib/ -name
'*.py' -exec grep 'from __main__ import' {} -ls \; ) 'from
__main__' is rare case so maybe it will be reasonable to
simply handle ImportError and print something like
'** 'from __main__ import' not supported' message.What do  
you think?       
  

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1429539&group_id=5470


More information about the Patches mailing list