[Lldb-commits] [PATCH] Delete port forwarding if ConnectRemote fails.
Oleksiy Vyalov
ovyalov at google.com
Fri Apr 3 16:12:44 PDT 2015
Hi tberghammer,
Since there is a possibility that we can call ConnectRemote a few times (for example, lldb-server is taking time to start) adding such precautionary measure to be sure that ConnectRemote doesn't introduce any leftovers.
http://reviews.llvm.org/D8826
Files:
source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
Index: source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
===================================================================
--- source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -80,13 +80,7 @@
bool
PlatformAndroidRemoteGDBServer::KillSpawnedProcess (lldb::pid_t pid)
{
- auto it = m_port_forwards.find (pid);
- if (it != m_port_forwards.end ())
- {
- DeleteForwardPortWithAdb (it->second.first, it->second.second);
- m_port_forwards.erase (it);
- }
-
+ DeleteForwardPort (pid);
return m_gdb_client.KillSpawnedProcess (pid);
}
@@ -109,18 +103,35 @@
m_port_forwards[g_remote_platform_pid] = std::make_pair (port, device_id);
- return PlatformRemoteGDBServer::ConnectRemote (args);
+ error = PlatformRemoteGDBServer::ConnectRemote (args);
+ if (error.Fail ())
+ DeleteForwardPort (g_remote_platform_pid);
+
+ return error;
}
Error
PlatformAndroidRemoteGDBServer::DisconnectRemote ()
{
- auto it = m_port_forwards.find (g_remote_platform_pid);
- if (it != m_port_forwards.end ())
- {
- DeleteForwardPortWithAdb (it->second.first, it->second.second);
- m_port_forwards.erase (it);
- }
-
+ DeleteForwardPort (g_remote_platform_pid);
return PlatformRemoteGDBServer::DisconnectRemote ();
}
+
+void
+PlatformAndroidRemoteGDBServer::DeleteForwardPort (lldb::pid_t pid)
+{
+ Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
+
+ auto it = m_port_forwards.find (pid);
+ if (it == m_port_forwards.end ())
+ return;
+
+ const auto& forward_val = it->second;
+ const auto error = DeleteForwardPortWithAdb (forward_val.first, forward_val.second);
+ if (error.Fail ()) {
+ if (log)
+ log->Printf ("Failed to delete port forwarding (pid=%" PRIu64 ", port=%d, device=%s): %s",
+ pid, forward_val.first, forward_val.second.c_str (), error.AsCString ());
+ }
+ m_port_forwards.erase (it);
+}
Index: source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
===================================================================
--- source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
+++ source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
@@ -45,6 +45,9 @@
bool
KillSpawnedProcess (lldb::pid_t pid) override;
+ void
+ DeleteForwardPort (lldb::pid_t pid);
+
private:
DISALLOW_COPY_AND_ASSIGN (PlatformAndroidRemoteGDBServer);
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8826.23243.patch
Type: text/x-patch
Size: 2562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150403/f3d4eb72/attachment.bin>
More information about the lldb-commits
mailing list