8000 gh-111051: Check if file is modifed during debugging in `pdb` by gaogaotiantian · Pull Request #111052 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 13 commits into from
Jan 25, 2024

Conversation

gaogaotiantian
Copy link
Member
@gaogaotiantian gaogaotiantian commented Oct 19, 2023

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 with time.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.

@gaogaotiantian
Copy link
Member Author

Hi @iritkatriel , do you have some time to take a look at this PR? Thanks!

@gaogaotiantian
Copy link
Member Author

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")
Copy link
Member

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".

Copy link
Member

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?

Copy link
Member Author

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.

gaogaotiantian and others added 2 commits January 24, 2024 13:32
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
@iritkatriel iritkatriel merged commit 8278fa2 into python:main Jan 25, 2024
@gaogaotiantian gaogaotiantian deleted the pdb-file-validation branch January 26, 2024 20:13
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0