mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
gh-90095: Make .pdbrc work properly and add some reasonable tests (#110496)
This commit is contained in:
parent
3c0dcef980
commit
44f9a84b67
3 changed files with 101 additions and 96 deletions
47
Lib/pdb.py
47
Lib/pdb.py
|
|
@ -363,26 +363,9 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
self._chained_exceptions[self._chained_exception_index],
|
||||
)
|
||||
|
||||
return self.execRcLines()
|
||||
|
||||
# Can be executed earlier than 'setup' if desired
|
||||
def execRcLines(self):
|
||||
if not self.rcLines:
|
||||
return
|
||||
# local copy because of recursion
|
||||
rcLines = self.rcLines
|
||||
rcLines.reverse()
|
||||
# execute every line only once
|
||||
self.rcLines = []
|
||||
while rcLines:
|
||||
line = rcLines.pop().strip()
|
||||
if line and line[0] != '#':
|
||||
if self.onecmd(line):
|
||||
# if onecmd returns True, the command wants to exit
|
||||
# from the interaction, save leftover rc lines
|
||||
# to execute before next interaction
|
||||
self.rcLines += reversed(rcLines)
|
||||
return True
|
||||
if self.rcLines:
|
||||
self.cmdqueue = self.rcLines
|
||||
self.rcLines = []
|
||||
|
||||
# Override Bdb methods
|
||||
|
||||
|
|
@ -571,12 +554,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
if isinstance(tb_or_exc, BaseException):
|
||||
assert tb is not None, "main exception must have a traceback"
|
||||
with self._hold_exceptions(_chained_exceptions):
|
||||
if self.setup(frame, tb):
|
||||
# no interaction desired at this time (happens if .pdbrc contains
|
||||
# a command like "continue")
|
||||
self.forget()
|
||||
return
|
||||
self.print_stack_entry(self.stack[self.curindex])
|
||||
self.setup(frame, tb)
|
||||
# if we have more commands to process, do not show the stack entry
|
||||
if not self.cmdqueue:
|
||||
self.print_stack_entry(self.stack[self.curindex])
|
||||
self._cmdloop()
|
||||
self.forget()
|
||||
|
||||
|
|
@ -712,7 +693,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
if marker >= 0:
|
||||
# queue up everything after marker
|
||||
next = line[marker+2:].lstrip()
|
||||
self.cmdqueue.append(next)
|
||||
self.cmdqueue.insert(0, next)
|
||||
line = line[:marker].rstrip()
|
||||
|
||||
# Replace all the convenience variables
|
||||
|
|
@ -737,13 +718,12 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
"""Handles one command line during command list definition."""
|
||||
cmd, arg, line = self.parseline(line)
|
||||
if not cmd:
|
||||
return
|
||||
return False
|
||||
if cmd == 'silent':
|
||||
self.commands_silent[self.commands_bnum] = True
|
||||
return # continue to handle other cmd def in the cmd list
|
||||
return False # continue to handle other cmd def in the cmd list
|
||||
elif cmd == 'end':
|
||||
self.cmdqueue = []
|
||||
return 1 # end of cmd list
|
||||
return True # end of cmd list
|
||||
cmdlist = self.commands[self.commands_bnum]
|
||||
if arg:
|
||||
cmdlist.append(cmd+' '+arg)
|
||||
|
|
@ -757,9 +737,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
# one of the resuming commands
|
||||
if func.__name__ in self.commands_resuming:
|
||||
self.commands_doprompt[self.commands_bnum] = False
|
||||
self.cmdqueue = []
|
||||
return 1
|
||||
return
|
||||
return True
|
||||
return False
|
||||
|
||||
# interface abstraction functions
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue