-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-131591: Allow pdb to attach to a running process #132451
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
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
5225333
Allow pdb to attach to a running process
godlygeek 78a3085
Remove 2 unused _RemotePdb instance attributes
godlygeek 90e0a81
Reduce duplication for 'debug' command
godlygeek e44a670
End commands entry on 'end' and ^C and ^D
godlygeek e837246
Set the frame for remote pdb to stop in explicitly
godlygeek 27efa97
Fix an unbound local in an error message
godlygeek 557a725
Clean up remote PDB detaching
godlygeek 7f7584a
Allow ctrl-c to interrupt a running process
godlygeek 5666ffb
Automatically detach if the client dies unexpectedly
godlygeek 325f166
Clear _last_pdb_instance on detach
godlygeek 72830e2
Refuse to attach if another PDB instance is installed
godlygeek 27c6780
Handle the confirmation prompt issued by 'clear'
godlygeek baaf28a
Make message and error handle non-string args
godlygeek e61cc31
Add some basic tests
pablogsal 5d59ce1
Don't use deprecated method
pablogsal 09adb2b
Try to prevent a PermissionError on Windows
godlygeek 600aa05
Address review comments
godlygeek 0601f10
Add protocol versioning and support -c commands
godlygeek 5a1755b
Fix tests to match new _connect signature for protocol versioning/com…
godlygeek f184e4e
Add some comments describing our protocol
godlygeek 82b71f8
Use the 'commands' state for '(com)' prompts
godlygeek 3986c17
Remove choices parameter from _prompt_for_confirmation
godlygeek 2e69667
Rename _RemotePdb to _PdbServer
godlygeek 55adbcc
Avoid fallthrough in signal handling
godlygeek 0bda5c2
Fix handling of a SystemExit raised in normal pdb mode
godlygeek 5e93247
Address nit
godlygeek f799e83
Use textwrap.dedent for test readability
godlygeek 46fb219
Drop dataclasses dependency
godlygeek 1ec9475
Combine the two blocks for handling -p PID into one
godlygeek 662c7eb
Add a news entry
godlygeek ac36d7d
Skip remote PDB integration test on WASI
godlygeek f06d9c2
Two small things missed in the previous fixes
godlygeek 715af27
Remove call to set_step in interrupt handler
godlygeek c654fdf
More tests
pablogsal 205bc55
More tests
pablogsal bbe784b
More tests
pablogsal 30cb537
Add what's new entry
pablogsal 659556f
use dedent
pablogsal 6c2d970
Add synchronization to test_keyboard_interrupt
godlygeek 100be44
Stop sending a "signal" message in test_keyboard_interrupt"
godlygeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
End commands entry on 'end' and ^C and ^D
- Loading branch information
commit e44a670b0c7a62642777197cc8402a71ca87114e
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we need to send these end commands back and forth? They are constants. Also
endis a very important one (arguably the most important one as it's in the example).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.
They're constants, but they're not necessarily the same constants for the client and the server, since they can be running different versions of Python.
If the attaching client is running 3.14.9 and the remote PDB server is running 3.14.0, it's possible that the client will think that some command should terminate the command list, and send a command list to the server that the server thinks is incomplete because it doesn't recognize that terminator. If that happened, we'd be out of sync - the server would still be waiting for more lines, and the client would think that it's done sending lines.
That said, perhaps I'm being overly defensive, and we shouldn't expect any new command to ever be added after 3.X final. But the risk of getting it wrong is leaving you with a broken debugger session that might only be able to be fixed by killing the client.
Another possible option is to be defensive in the:
loop below. We could say that loop must break, and that if it doesn't, it can only mean that we got a list that was unterminated, and so we should roll back to the old set of commands. If you prefer that over sending list of early-command-terminators back over the wire, I'm fine with that.
That'd just be something like (pseudocode):
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.
That won't happen. When the client sent the commands as a list, the server will just finish the list and consider it done for the commands. Nothing worse would happen.
Also, I don't expect the list of resuming commands to change. And as discussed elsewhere, I don't think we should support cross version debugging.
I just tested it and
CTRL+Ddoes not work either (to terminate the commands).Uh oh!
There was an error while loading. Please reload this page.
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.
Ah, you're right - I misremembered and thought that
_RemotePdbsetsself.commands_defining = True, but it doesn't (it used to in one of my earlier iterations).OK, in that case, the only reason I can think of to send the list of resuming commands from the remote to the client is aliases. Currently I'm not handling that, and I'm just hardcoding, but in regular PDB you can:
Note that
blahended the command list. The only way we can support that for remote PDB is to send the list of resuming commands from the server to the client. But, I also don't care much if we support that. As you say, if we don't, the only impact is that the user needs to a) use the regular command instead of the alias, or b) add anendcommand.That seems fine to me. I think that having the resuming commands end the command list is a weird feature anyway, but I was aiming for feature parity.
So: if you care about aliases for resuming commands ending the commands list, I'll keep this code and update it to also send the list of aliases that expand to one of the commands in the list.
If you don't care about aliases for resuming commands ending the command list, I'm happy to hardcode the list client-side instead.
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.
Not for regular PDB either, so that's fine.
But ctrl-c just kills the whole remote pdb client, that's wrong.
lol oops, that's what I get for focusing on edge cases 🤣
Fixed 'end' and ctrl-c in e44a670
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.
I believe the only "correct" way to do this is to send the commands to the server one by one - you'll never get the correct result with client parsing. For example,
x = 1;;continueshould end the command prompt, and the current client does not do that. Unless you parse everything exactly as the server does, you won't get the same result.For your
blahexample - the current code does not handle it, and it would be complicated to make it work properly. If we want to make it right, we need to simulate the send/receive line by line.The worse case in the current implementation is that the user needs to end the command with an
end- that's not too bad. We can do it for now.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.
Oof, yeah. I didn't think about
;;I can do that. It wouldn't be too tough, and it would wind up looking a lot like
interact- set a flag for the "mode", and make it be possible for the client to return to command mode (on ctrl-c or ctrl-d) or for the server to (when the command list is terminated).I understand how to do this, and it wouldn't be difficult, but it would be almost exactly as complex as
interact, for better or worse.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.
Addressed in 600aa05