@@ -519,7 +519,7 @@ def _validate_file_mtime(self):
519519
520520 # Called before loop, handles display expressions
521521 # Set up convenience variable containers
522- def preloop (self ):
522+ def _show_display (self ):
523523 displaying = self .displaying .get (self .curframe )
524524 if displaying :
525525 for expr , oldvalue in displaying .items ():
@@ -607,15 +607,13 @@ def interaction(self, frame, tb_or_exc):
607607 self .setup (frame , tb )
608608 # We should print the stack entry if and only if the user input
609609 # is expected, and we should print it right before the user input.
610- # If self.cmdqueue is not empty, we append a "w 0" command to the
611- # queue, which is equivalent to print_stack_entry
612- if self .cmdqueue :
613- self .cmdqueue .append ('w 0' )
614- else :
615- self .print_stack_entry (self .stack [self .curindex ])
610+ # We achieve this by appending _pdbcmd_print_frame_status to the
611+ # command queue. If cmdqueue is not exausted, the user input is
612+ # not expected and we will not print the stack entry.
613+ self .cmdqueue .append ('_pdbcmd_print_frame_status' )
616614 self ._cmdloop ()
617- # If "w 0" is not used, pop it out
618- if self .cmdqueue and self .cmdqueue [- 1 ] == 'w 0 ' :
615+ # If _pdbcmd_print_frame_status is not used, pop it out
616+ if self .cmdqueue and self .cmdqueue [- 1 ] == '_pdbcmd_print_frame_status ' :
619617 self .cmdqueue .pop ()
620618 self .forget ()
621619
@@ -848,6 +846,10 @@ def onecmd(self, line):
848846 """
849847 if not self .commands_defining :
850848 self ._validate_file_mtime ()
849+ if line .startswith ('_pdbcmd' ):
850+ command , arg , line = self .parseline (line )
851+ if hasattr (self , command ):
852+ return getattr (self , command )(arg )
851853 return cmd .Cmd .onecmd (self , line )
852854 else :
853855 return self .handle_command_def (line )
@@ -981,6 +983,12 @@ def completedefault(self, text, line, begidx, endidx):
981983 state += 1
982984 return matches
983985
986+ # Pdb meta commands, only intended to be used internally by pdb
987+
988+ def _pdbcmd_print_frame_status (self , arg ):
989+ self .print_stack_entry (self .stack [self .curindex ])
990+ self ._show_display ()
991+
984992 # Command definitions, called by cmdloop()
985993 # The argument is the remaining string on the command line
986994 # Return true to exit from the command loop
@@ -1411,24 +1419,16 @@ def do_clear(self, arg):
14111419 complete_cl = _complete_location
14121420
14131421 def do_where (self , arg ):
1414- """w(here) [count]
1422+ """w(here)
14151423
1416- Print a stack trace. If count is not specified, print the full stack.
1417- If count is 0, print the current frame entry. If count is positive,
1418- print count entries from the most recent frame. If count is negative,
1419- print -count entries from the least recent frame.
1424+ Print a stack trace, with the most recent frame at the bottom.
14201425 An arrow indicates the "current frame", which determines the
14211426 context of most commands. 'bt' is an alias for this command.
14221427 """
1423- if not arg :
1424- count = None
1425- else :
1426- try :
1427- count = int (arg )
1428- except ValueError :
1429- self .error ('Invalid count (%s)' % arg )
1430- return
1431- self .print_stack_trace (count )
1428+ if arg :
1429+ self ._print_invalid_arg (arg )
1430+ return
1431+ self .print_stack_trace ()
14321432 do_w = do_where
14331433 do_bt = do_where
14341434
@@ -2083,22 +2083,10 @@ def complete_unalias(self, text, line, begidx, endidx):
20832083 # It is also consistent with the up/down commands (which are
20842084 # compatible with dbx and gdb: up moves towards 'main()'
20852085 # and down moves towards the most recent stack frame).
2086- # * if count is None, prints the full stack
2087- # * if count = 0, prints the current frame entry
2088- # * if count < 0, prints -count least recent frame entries
2089- # * if count > 0, prints count most recent frame entries
2090-
2091- def print_stack_trace (self , count = None ):
2092- if count is None :
2093- stack_to_print = self .stack
2094- elif count == 0 :
2095- stack_to_print = [self .stack [self .curindex ]]
2096- elif count < 0 :
2097- stack_to_print = self .stack [:- count ]
2098- else :
2099- stack_to_print = self .stack [- count :]
2086+
2087+ def print_stack_trace (self ):
21002088 try :
2101- for frame_lineno in stack_to_print :
2089+ for frame_lineno in self . stack :
21022090 self .print_stack_entry (frame_lineno )
21032091 except KeyboardInterrupt :
21042092 pass
0 commit comments