Skip to content

Commit

Permalink
[lldb/platform-gdb] Clear cached protocol state upon disconnection
Browse files Browse the repository at this point in the history
Previously we would persist the flags indicating whether the remote side
supports a particular feature across reconnects, which is obviously not
a good idea.

I implement the clearing by nuking (its the only way to be sure :) the
entire GDBRemoteCommunication object in the disconnect operation and
creating a new one upon connection. This allows us to maintain a nice
invariant that the GDBRemoteCommunication object (which is now a
pointer) exists only if it is connected. The downside to that is that a
lot of functions now needs to check the validity of the pointer instead
of blindly accessing the object.

The process communication does not suffer from the same issue because we
always destroy the entire Process object for a relaunch.

Differential Revision: https://reviews.llvm.org/D116539
  • Loading branch information
labath committed Jan 10, 2022
1 parent d0ee094 commit 8ccfcab
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 63 deletions.
5 changes: 3 additions & 2 deletions lldb/packages/Python/lldbsuite/test/lldbgdbclient.py
Expand Up @@ -58,7 +58,7 @@ def connect(self, target):
self.assertTrue(process, PROCESS_IS_VALID)
return process

def assertPacketLogContains(self, packets):
def assertPacketLogContains(self, packets, log=None):
"""
Assert that the mock server's packet log contains the given packets.
Expand All @@ -69,9 +69,10 @@ def assertPacketLogContains(self, packets):
The check does not require that the packets be consecutive, but does
require that they are ordered in the log as they ordered in the arg.
"""
if log is None:
log = self.server.responder.packetLog
i = 0
j = 0
log = self.server.responder.packetLog

while i < len(packets) and j < len(log):
if log[j] == packets[i]:
Expand Down
Expand Up @@ -82,9 +82,11 @@ PlatformAndroidRemoteGDBServer::~PlatformAndroidRemoteGDBServer() {

bool PlatformAndroidRemoteGDBServer::LaunchGDBServer(lldb::pid_t &pid,
std::string &connect_url) {
assert(IsConnected());
uint16_t remote_port = 0;
std::string socket_name;
if (!m_gdb_client.LaunchGDBServer("127.0.0.1", pid, remote_port, socket_name))
if (!m_gdb_client_up->LaunchGDBServer("127.0.0.1", pid, remote_port,
socket_name))
return false;

Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
Expand All @@ -98,8 +100,9 @@ bool PlatformAndroidRemoteGDBServer::LaunchGDBServer(lldb::pid_t &pid,
}

bool PlatformAndroidRemoteGDBServer::KillSpawnedProcess(lldb::pid_t pid) {
assert(IsConnected());
DeleteForwardPort(pid);
return m_gdb_client.KillSpawnedProcess(pid);
return m_gdb_client_up->KillSpawnedProcess(pid);
}

Status PlatformAndroidRemoteGDBServer::ConnectRemote(Args &args) {
Expand Down

0 comments on commit 8ccfcab

Please sign in to comment.