summaryrefslogtreecommitdiffstats
path: root/Lib/pdb.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-xLib/pdb.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 3e5e898..683abb9 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -171,14 +171,18 @@ class Pdb(bdb.Bdb, cmd.Cmd):
def user_return(self, frame, return_value):
"""This function is called when a return trap is set here."""
+ if self._wait_for_mainpyfile:
+ return
frame.f_locals['__return__'] = return_value
print >>self.stdout, '--Return--'
self.interaction(frame, None)
def user_exception(self, frame, exc_info):
- exc_type, exc_value, exc_traceback = exc_info
"""This function is called if an exception occurs,
but only if we are to stop at or just below this level."""
+ if self._wait_for_mainpyfile:
+ return
+ exc_type, exc_value, exc_traceback = exc_info
frame.f_locals['__exception__'] = exc_type, exc_value
if type(exc_type) == type(''):
exc_type_name = exc_type
@@ -265,8 +269,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
return self.handle_command_def(line)
def handle_command_def(self,line):
- """ Handles one command line during command list definition. """
+ """Handles one command line during command list definition."""
cmd, arg, line = self.parseline(line)
+ if not cmd:
+ return
if cmd == 'silent':
self.commands_silent[self.commands_bnum] = True
return # continue to handle other cmd def in the cmd list
@@ -274,7 +280,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
self.cmdqueue = []
return 1 # end of cmd list
cmdlist = self.commands[self.commands_bnum]
- if (arg):
+ if arg:
cmdlist.append(cmd+' '+arg)
else:
cmdlist.append(cmd)
@@ -313,9 +319,11 @@ class Pdb(bdb.Bdb, cmd.Cmd):
prompt_back = self.prompt
self.prompt = '(com) '
self.commands_defining = True
- self.cmdloop()
- self.commands_defining = False
- self.prompt = prompt_back
+ try:
+ self.cmdloop()
+ finally:
+ self.commands_defining = False
+ self.prompt = prompt_back
def do_break(self, arg, temporary = 0):
# break [ ([filename:]lineno | function) [, "condition"] ]
@@ -451,7 +459,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank
line or EOF). Warning: testing is not comprehensive.
"""
- line = linecache.getline(filename, lineno, self.curframe.f_globals)
+ # this method should be callable before starting debugging, so default
+ # to "no globals" if there is no current frame
+ globs = self.curframe.f_globals if hasattr(self, 'curframe') else None
+ line = linecache.getline(filename, lineno, globs)
if not line:
print >>self.stdout, 'End of file'
return 0
@@ -1280,7 +1291,7 @@ def main():
# changed by the user from the command line. There is a "restart" command which
# allows explicit specification of command line arguments.
pdb = Pdb()
- while 1:
+ while True:
try:
pdb._runscript(mainpyfile)
if pdb._user_requested_quit: