summaryrefslogtreecommitdiffstats
path: root/Lib/pdb.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-06-27 10:37:48 (GMT)
committerGeorg Brandl <georg@python.org>2010-06-27 10:37:48 (GMT)
commiteb1f4aa2321e5ac19e3139858c09e5b1c7acc668 (patch)
treede43df1847e77c29286046e0d34a6549c6ec3479 /Lib/pdb.py
parent952867aa306dda2a710df4c286b5d9f0593e3d34 (diff)
downloadcpython-eb1f4aa2321e5ac19e3139858c09e5b1c7acc668.zip
cpython-eb1f4aa2321e5ac19e3139858c09e5b1c7acc668.tar.gz
cpython-eb1f4aa2321e5ac19e3139858c09e5b1c7acc668.tar.bz2
#9064: accept number of frames for "up" and "down" commands in pdb.
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-xLib/pdb.py38
1 files changed, 28 insertions, 10 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index b15a3d1..43520d6 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -618,26 +618,44 @@ class Pdb(bdb.Bdb, cmd.Cmd):
do_w = do_where
do_bt = do_where
+ def _select_frame(self, number):
+ assert 0 <= number < len(self.stack)
+ self.curindex = number
+ self.curframe = self.stack[self.curindex][0]
+ self.curframe_locals = self.curframe.f_locals
+ self.print_stack_entry(self.stack[self.curindex])
+ self.lineno = None
+
def do_up(self, arg):
if self.curindex == 0:
print('*** Oldest frame', file=self.stdout)
+ return
+ try:
+ count = int(arg or 1)
+ except ValueError:
+ print('*** Invalid frame count (%s)' % arg, file=self.stdout)
+ return
+ if count < 0:
+ newframe = 0
else:
- self.curindex = self.curindex - 1
- self.curframe = self.stack[self.curindex][0]
- self.curframe_locals = self.curframe.f_locals
- self.print_stack_entry(self.stack[self.curindex])
- self.lineno = None
+ newframe = max(0, self.curindex - count)
+ self._select_frame(newframe)
do_u = do_up
def do_down(self, arg):
if self.curindex + 1 == len(self.stack):
print('*** Newest frame', file=self.stdout)
+ return
+ try:
+ count = int(arg or 1)
+ except ValueError:
+ print('*** Invalid frame count (%s)' % arg, file=self.stdout)
+ return
+ if count < 0:
+ newframe = len(self.stack) - 1
else:
- self.curindex = self.curindex + 1
- self.curframe = self.stack[self.curindex][0]
- self.curframe_locals = self.curframe.f_locals
- self.print_stack_entry(self.stack[self.curindex])
- self.lineno = None
+ newframe = min(len(self.stack) - 1, self.curindex + count)
+ self._select_frame(newframe)
do_d = do_down
def do_until(self, arg):