(original) (raw)
Index: pdb.py =================================================================== --- pdb.py (revision 42261) +++ pdb.py (working copy) @@ -967,12 +967,17 @@ return None def _runscript(self, filename): - # Start with fresh empty copy of globals and locals and tell the script - # that it's being run as __main__ to avoid scripts being able to access - # the pdb.py namespace. - globals_ = {"__name__" : "__main__"} - locals_ = globals_ - + # note: the script will run in pdb.py namespace (pdb's globals + # are shared with script's globals).. And if your program has + # a help symbol, then "help pdb" will not work from pdb cmd line. + # While this is bad, the only alternative would be to do: + # globals_ = locals_={"__name__" : "__main__"} + # but that breaks any programs doing "from __main__ import" + # (as __main__ would be pdb's namespace) which is, probably, + # worse.. What we could/should do is to reduce the number + # of global symbols in pdb + + # When bdb sets tracing, a number of call and line events happens # BEFORE debugger even reaches user's code (and the exact sequence of # events depends on python version). So we take special measures to @@ -982,7 +987,7 @@ self.mainpyfile = self.canonic(filename) self._user_requested_quit = 0 statement = 'execfile( "%s")' % filename - self.run(statement, globals=globals_, locals=locals_) + self.run(statement) # Simplified interface @@ -1078,4 +1083,5 @@ # When invoked as main program, invoke the debugger on a script if __name__=='__main__': - main() + import pdb + pdb.main()