Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3256,6 +3256,7 @@ Status Process::ConnectRemote(llvm::StringRef remote_url) {
if (state == eStateStopped || state == eStateCrashed) {
// If we attached and actually have a process on the other end, then
// this ended up being the equivalent of an attach.
SetShouldDetach(true);
CompleteAttach();

// This delays passing the stopped event to listeners till
Expand Down
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"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check that no k was received. Since it's cheap to do and might catch a silly mistake.

Loading