Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb1f4aa

Browse files
committed
#9064: accept number of frames for "up" and "down" commands in pdb.
1 parent 952867a commit eb1f4aa

4 files changed

Lines changed: 42 additions & 20 deletions

File tree

Doc/library/pdb.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,13 @@ w(here)
210210
Print a stack trace, with the most recent frame at the bottom. An arrow
211211
indicates the current frame, which determines the context of most commands.
212212

213-
d(own)
214-
Move the current frame one level down in the stack trace (to a newer frame).
213+
d(own) [*count*]
214+
Move the current frame *count* (default one) levels down in the stack trace
215+
(to a newer frame).
215216

216-
u(p)
217-
Move the current frame one level up in the stack trace (to an older frame).
217+
u(p) [*count*]
218+
Move the current frame *count* (default one) levels up in the stack trace
219+
(to an older frame).
218220

219221
b(reak) [[*filename*:]\ *lineno* | *function*\ [, *condition*]]
220222
With a *lineno* argument, set a break there in the current file. With a

Lib/pdb.doc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ w(here)
6868
An arrow indicates the "current frame", which determines the
6969
context of most commands.
7070

71-
d(own)
72-
Move the current frame one level down in the stack trace
73-
(to a newer frame).
71+
d(own) [ count ]
72+
Move the current frame count (default one) levels down in the
73+
stack trace (to a newer frame).
7474

75-
u(p)
76-
Move the current frame one level up in the stack trace
77-
(to an older frame).
75+
u(p) [ count ]
76+
Move the current frame count (default one) levels up in the
77+
stack trace (to an older frame).
7878

7979
b(reak) [ ([filename:]lineno | function) [, condition] ]
8080
With a filename:line number argument, set a break there. If

Lib/pdb.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -618,26 +618,44 @@ def do_where(self, arg):
618618
do_w = do_where
619619
do_bt = do_where
620620

621+
def _select_frame(self, number):
622+
assert 0 <= number < len(self.stack)
623+
self.curindex = number
624+
self.curframe = self.stack[self.curindex][0]
625+
self.curframe_locals = self.curframe.f_locals
626+
self.print_stack_entry(self.stack[self.curindex])
627+
self.lineno = None
628+
621629
def do_up(self, arg):
622630
if self.curindex == 0:
623631
print('*** Oldest frame', file=self.stdout)
632+
return
633+
try:
634+
count = int(arg or 1)
635+
except ValueError:
636+
print('*** Invalid frame count (%s)' % arg, file=self.stdout)
637+
return
638+
if count < 0:
639+
newframe = 0
624640
else:
625-
self.curindex = self.curindex - 1
626-
self.curframe = self.stack[self.curindex][0]
627-
self.curframe_locals = self.curframe.f_locals
628-
self.print_stack_entry(self.stack[self.curindex])
629-
self.lineno = None
641+
newframe = max(0, self.curindex - count)
642+
self._select_frame(newframe)
630643
do_u = do_up
631644

632645
def do_down(self, arg):
633646
if self.curindex + 1 == len(self.stack):
634647
print('*** Newest frame', file=self.stdout)
648+
return
649+
try:
650+
count = int(arg or 1)
651+
except ValueError:
652+
print('*** Invalid frame count (%s)' % arg, file=self.stdout)
653+
return
654+
if count < 0:
655+
newframe = len(self.stack) - 1
635656
else:
636-
self.curindex = self.curindex + 1
637-
self.curframe = self.stack[self.curindex][0]
638-
self.curframe_locals = self.curframe.f_locals
639-
self.print_stack_entry(self.stack[self.curindex])
640-
self.lineno = None
657+
newframe = min(len(self.stack) - 1, self.curindex + count)
658+
self._select_frame(newframe)
641659
do_d = do_down
642660

643661
def do_until(self, arg):

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ C-API
456456
Library
457457
-------
458458

459+
- Issue #9064: pdb's "up" and "down" commands now accept an optional argument.
460+
459461
- Issue #9018: os.path.normcase() now raises a TypeError if the argument is
460462
not ``str`` or ``bytes``.
461463

0 commit comments

Comments
 (0)