-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-111051: Check if file is modifed during debugging in pdb
#111052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hi @iritkatriel , do you have some time to take a look at this PR? Thanks! |
Friendly ping @iritkatriel , this is brought up in #112952 again so users are having confusions about it. We basically only add a warning message to users when the files were changed. |
Lib/pdb.py
Outdated
if (filename in self._file_mtime_table and | ||
mtime != self._file_mtime_table[filename]): | ||
self.message(f"*** WARNING: file '{filename}' was edited after pdb started, " | ||
"running stale code until restart") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "until program is rerun" actually. I think this could look like "until restart of pdb".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also, "after pdb restarted" is not quite accurate, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the full truth but it's accurate. If the user sees this warning, then the file must be edited after pdb started. However, it's possible that the file was edited after the pdb started, but the warning was not generated - because of how we detect this kind of issue.
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This added a sanity check for file modification. If the file is modified during debugging, a warning will be generated.
You'll probably be tempted to use
os.path.getmtime()
in combination withtime.time()
on pdb initialization, but mtime's resolution is not perfect and there can be issues (for example, the test has to explicitly wait for a while to work). On the other hand, this implementation generates 0 false positive and 0 false negative if the file is seen at least once by pdb. It does not work if the pdb never executes a frame in the file, but the file is somehow modifed after pdb started.The behavior is clear and independent of the resolution of system clock/file system.
We can make a heuristic check for the files, which has it own issue - what if the module is modified between pdb started and the module is loaded?
Overall I believe this implementation is absolutely better than what we have now.