-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb] Correctly detach (rather than kill) when connecting with gdb-remote #166869
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
2 commits
Select commit
Hold shift + click to select a range
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
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
64 changes: 64 additions & 0 deletions
64
lldb/test/API/functionalities/gdb_remote_client/TestConnectRemoteDetach.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """ | ||
| Test that ConnectRemote sets ShouldDetach flag correctly. | ||
|
|
||
| When connecting to a remote process that stops after connection, | ||
| the process should be marked for detach (not kill) on destruction. | ||
| """ | ||
|
|
||
| import lldb | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test.gdbclientutils import * | ||
| from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
|
|
||
| class TestConnectRemoteDetach(GDBRemoteTestBase): | ||
| """Test that ConnectRemote properly sets ShouldDetach flag.""" | ||
|
|
||
| class StoppedResponder(MockGDBServerResponder): | ||
| """A responder that returns a stopped process.""" | ||
|
|
||
| def qfThreadInfo(self): | ||
| return "m1" | ||
|
|
||
| def qsThreadInfo(self): | ||
| return "l" | ||
|
|
||
| def qC(self): | ||
| return "QC1" | ||
|
|
||
| def haltReason(self): | ||
| # Return that we're stopped | ||
| return "T05thread:1;" | ||
|
|
||
| def cont(self): | ||
| # Stay stopped | ||
| return "T05thread:1;" | ||
|
|
||
| def D(self): | ||
| # Detach packet - this is what we want to verify gets called | ||
| return "OK" | ||
|
|
||
| def test_connect_remote_sets_detach(self): | ||
| """Test that ConnectRemote to a stopped process sets ShouldDetach.""" | ||
| self.server.responder = self.StoppedResponder() | ||
|
|
||
| target = self.createTarget("a.yaml") | ||
| process = self.connect(target) | ||
|
|
||
| # Wait for the process to be in stopped state after connecting. | ||
| # When ConnectRemote connects to a remote process that is stopped, | ||
| # it should call SetShouldDetach(true) before CompleteAttach(). | ||
| lldbutil.expect_state_changes( | ||
| self, self.dbg.GetListener(), process, [lldb.eStateStopped] | ||
| ) | ||
|
|
||
| # Now destroy the process. Because ShouldDetach was set to true | ||
| # during ConnectRemote, this should send a 'D' (detach) packet | ||
| # rather than a 'k' (kill) packet when the process is destroyed. | ||
| process.Destroy() | ||
|
|
||
| # Verify that the detach packet was sent | ||
| # The 'D' packet is the detach command in GDB remote protocol | ||
| self.assertPacketLogReceived(["D"]) | ||
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.
Also check that no
kwas received. Since it's cheap to do and might catch a silly mistake.