@@ -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 ):
0 commit comments