[Lldb-commits] [lldb] r156024 - in /lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote: GDBRemoteCommunicationServer.cpp GDBRemoteCommunicationServer.h

Johnny Chen johnny.chen at apple.com
Wed May 2 14:33:04 PDT 2012


Author: johnny
Date: Wed May  2 16:33:04 2012
New Revision: 156024

URL: http://llvm.org/viewvc/llvm-project?rev=156024&view=rev
Log:
Use an instance variable m_next_port to track the next port to start the debugserver with.
Add a member function GetAndUpdateNextPort() to get-and-update the next port to use.

Modified:
    lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
    lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h

Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=156024&r1=156023&r2=156024&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Wed May  2 16:33:04 2012
@@ -45,9 +45,7 @@
     m_proc_infos_index (0),
     m_lo_port_num (0),
     m_hi_port_num (0),
-    m_ports (),
-    m_mutex (Mutex::eMutexTypeRecursive),
-    m_port_index (0),
+    m_next_port (0),
     m_use_port_range (false)
 {
     // We seldom need to override the port number that the debugserver process
@@ -728,7 +726,7 @@
         ConnectionFileDescriptor file_conn;
         char connect_url[PATH_MAX];
         Error error;
-        char unix_socket_name[PATH_MAX] = "/tmp/XXXXXX";    
+        char unix_socket_name[PATH_MAX] = "/tmp/XXXXXX";
         if (::mktemp (unix_socket_name) == NULL)
         {
             error.SetErrorString ("failed to make temporary path for a unix socket");
@@ -745,9 +743,15 @@
             
             if (IS_VALID_LLDB_HOST_THREAD(accept_thread))
             {
-                // Spawn a debugserver and try to get
+                // Spawn a debugserver and try to get the port it listens to.
                 ProcessLaunchInfo debugserver_launch_info;
-                error = StartDebugserverProcess ("localhost:0", 
+                char host_and_port[256];
+                const int host_and_port_len = ::snprintf (host_and_port,
+                                                          sizeof(host_and_port), 
+                                                          "localhost:%u", 
+                                                          GetAndUpdateNextPort());
+                assert (host_and_port_len < sizeof(host_and_port));
+                error = StartDebugserverProcess (host_and_port,
                                                  unix_socket_name, 
                                                  debugserver_launch_info);
                 

Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h?rev=156024&r1=156023&r2=156024&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h Wed May  2 16:33:04 2012
@@ -15,7 +15,6 @@
 #include <vector>
 // Other libraries and framework includes
 // Project includes
-#include "lldb/Host/Mutex.h"
 #include "lldb/Target/Process.h"
 #include "GDBRemoteCommunication.h"
 
@@ -63,9 +62,21 @@
         m_hi_port_num = hi_port_num;
     }
 
+    // If we are using a port range, get and update the next port to be used variable.
+    // Otherwise, just return 0.
+    uint16_t
+    GetAndUpdateNextPort ()
+    {
+        if (!m_use_port_range)
+            return 0;
+        int16_t val = m_next_port;
+        if (++m_next_port > m_hi_port_num)
+            m_next_port = m_lo_port_num;
+        return val;
+    }
+
 protected:
     //typedef std::map<uint16_t, lldb::pid_t> PortToPIDMap;
-    typedef std::vector<uint16_t> port_vector;
 
     lldb::thread_t m_async_thread;
     lldb_private::ProcessLaunchInfo m_process_launch_info;
@@ -75,9 +86,7 @@
     uint16_t m_lo_port_num;
     uint16_t m_hi_port_num;
     //PortToPIDMap m_port_to_pid_map;
-    port_vector m_ports;
-    mutable lldb_private::Mutex m_mutex;
-    size_t m_port_index;
+    uint16_t m_next_port;
     bool m_use_port_range;
 
     size_t





More information about the lldb-commits mailing list