@@ -402,6 +402,8 @@ def setup(self, f, tb):
402402 self .curframe = self .stack [self .curindex ][0 ]
403403 self .set_convenience_variable (self .curframe , '_frame' , self .curframe )
404404
405+ self ._save_initial_file_mtime (self .curframe )
406+
405407 if self ._chained_exceptions :
406408 self .set_convenience_variable (
407409 self .curframe ,
@@ -494,9 +496,21 @@ def _cmdloop(self):
494496 except KeyboardInterrupt :
495497 self .message ('--KeyboardInterrupt--' )
496498
499+ def _save_initial_file_mtime (self , frame ):
500+ """save the mtime of the all the files in the frame stack in the file mtime table
501+ if they haven't been saved yet."""
502+ while frame :
503+ filename = frame .f_code .co_filename
504+ if filename not in self ._file_mtime_table :
505+ try :
506+ self ._file_mtime_table [filename ] = os .path .getmtime (filename )
507+ except Exception :
508+ pass
509+ frame = frame .f_back
510+
497511 def _validate_file_mtime (self ):
498- """Check if the source file of the current frame has been modified since
499- the last time we saw it. If so, give a warning."""
512+ """Check if the source file of the current frame has been modified.
513+ If so, give a warning and reset the modify time to current ."""
500514 try :
501515 filename = self .curframe .f_code .co_filename
502516 mtime = os .path .getmtime (filename )
@@ -506,7 +520,7 @@ def _validate_file_mtime(self):
506520 mtime != self ._file_mtime_table [filename ]):
507521 self .message (f"*** WARNING: file '{ filename } ' was edited, "
508522 "running stale code until the program is rerun" )
509- self ._file_mtime_table [filename ] = mtime
523+ self ._file_mtime_table [filename ] = mtime
510524
511525 # Called before loop, handles display expressions
512526 # Set up convenience variable containers
@@ -836,7 +850,6 @@ def onecmd(self, line):
836850 a breakpoint command list definition.
837851 """
838852 if not self .commands_defining :
839- self ._validate_file_mtime ()
840853 if line .startswith ('_pdbcmd' ):
841854 command , arg , line = self .parseline (line )
842855 if hasattr (self , command ):
@@ -980,6 +993,7 @@ def completedefault(self, text, line, begidx, endidx):
980993
981994 def _pdbcmd_print_frame_status (self , arg ):
982995 self .print_stack_trace (0 )
996+ self ._validate_file_mtime ()
983997 self ._show_display ()
984998
985999 def _pdbcmd_silence_frame_status (self , arg ):
@@ -1861,6 +1875,7 @@ def do_list(self, arg):
18611875 self .message ('[EOF]' )
18621876 except KeyboardInterrupt :
18631877 pass
1878+ self ._validate_file_mtime ()
18641879 do_l = do_list
18651880
18661881 def do_longlist (self , arg ):
@@ -1879,6 +1894,7 @@ def do_longlist(self, arg):
18791894 self .error (err )
18801895 return
18811896 self ._print_lines (lines , lineno , breaklist , self .curframe )
1897+ self ._validate_file_mtime ()
18821898 do_ll = do_longlist
18831899
18841900 def do_source (self , arg ):
0 commit comments