Commits

Matt McClure  committed 866808c

Add a pdb frame command.

Number frames when pdb prints the stack.

  • Participants
  • Parent commits 4a17784
  • Branches pdb-number-stack-frames-2.6

Comments (0)

Files changed (1)

     do_w = do_where
     do_bt = do_where
 
+    def do_frame(self, arg):
+        try:
+            arg = int(arg)
+        except (ValueError, TypeError):
+            print >>self.stdout, '*** Expected a number, got "{0}"'.format(arg)
+            return
+        if arg < 0 or arg >= len(self.stack):
+            print >>self.stdout, '*** Out of range'
+        else:
+            self.curindex = arg
+            self.curframe = self.stack[self.curindex][0]
+            self.print_stack_entry(self.stack[self.curindex])
+            self.lineno = None
+    do_f = do_frame
+
     def do_up(self, arg):
-        if self.curindex == 0:
+        arg = '1' if arg == '' else arg
+        try:
+            arg = int(arg)
+        except (ValueError, TypeError):
+            print >>self.stdout, '*** Expected a number, got "{0}"'.format(arg)
+            return
+        if self.curindex - arg < 0:
             print >>self.stdout, '*** Oldest frame'
         else:
-            self.curindex = self.curindex - 1
+            self.curindex = self.curindex - arg
             self.curframe = self.stack[self.curindex][0]
             self.print_stack_entry(self.stack[self.curindex])
             self.lineno = None
     do_u = do_up
 
-    def do_down(self, arg):
-        if self.curindex + 1 == len(self.stack):
+    def do_down(self, arg='1'):
+        arg = '1' if arg == '' else arg
+        try:
+            arg = int(arg)
+        except (ValueError, TypeError):
+            print >>self.stdout, '*** Expected a number, got "{0}"'.format(arg)
+            return
+        if self.curindex + arg >= len(self.stack):
             print >>self.stdout, '*** Newest frame'
         else:
-            self.curindex = self.curindex + 1
+            self.curindex = self.curindex + arg
             self.curframe = self.stack[self.curindex][0]
             self.print_stack_entry(self.stack[self.curindex])
             self.lineno = None
 
     def print_stack_trace(self):
         try:
-            for frame_lineno in self.stack:
-                self.print_stack_entry(frame_lineno)
+            for frame_index, frame_lineno in enumerate(self.stack):
+                self.print_stack_entry(frame_lineno, frame_index=frame_index)
         except KeyboardInterrupt:
             pass
 
-    def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix):
+    def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix, frame_index=None):
+        frame_index = (frame_index if frame_index is not None else
+                       self.curindex)
         frame, lineno = frame_lineno
         if frame is self.curframe:
-            print >>self.stdout, '>',
+            print >>self.stdout, ('[%d]\n>' % frame_index),
         else:
-            print >>self.stdout, ' ',
+            print >>self.stdout, ('[%d]\n ' % frame_index),
         print >>self.stdout, self.format_stack_entry(frame_lineno,
                                                      prompt_prefix)