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

Johnny Chen johnny.chen at apple.com
Tue May 1 18:11:39 PDT 2012


Author: johnny
Date: Tue May  1 20:11:38 2012
New Revision: 155972

URL: http://llvm.org/viewvc/llvm-project?rev=155972&view=rev
Log:
o PlatformRemoteGDBServer.cpp:

Add the capability for PlatformRemoteGDBServer::Attach() to override the normal behavior of
constructing its connect_url based upon GetHostname() and port dynamically.  Use two environment
variables LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME and LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET
to override the hostname part and to add an offset to the port number.

o GDBRemoteCommunicationServer.cpp/h:

On the lldb-platform side, provide a way to specify the port range that the debugserver process
starts with.  By default, we pass in 0 to let the system choose a random port for the debugserver.
In rare situation where the need arises, use two environment variables to override the lo_port_num
and the hi_port_num, i.e., LLDB_PLATFORM_START_DEBUG_SERVER_LO_PORT and LLDB_PLATFORM_START_DEBUG_SERVER_HI_PORT.

--------------------------------------------------------------------------------
work in progress for: rdar://problem/11352190

Modified:
    lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
    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/Platform/gdb-server/PlatformRemoteGDBServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp?rev=155972&r1=155971&r2=155972&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp Tue May  1 20:11:38 2012
@@ -399,11 +399,14 @@
                     if (process_sp)
                     {
                         char connect_url[256];
+                        const char *override_hostname = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME");
+                        const char *port_offset_c_str = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET");
+                        int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0;
                         const int connect_url_len = ::snprintf (connect_url, 
                                                                 sizeof(connect_url), 
                                                                 "connect://%s:%u", 
-                                                                GetHostname (), 
-                                                                port);
+                                                                override_hostname ? override_hostname : GetHostname (), 
+                                                                port + port_offset);
                         assert (connect_url_len < sizeof(connect_url));
                         error = process_sp->ConnectRemote (connect_url);
                         if (error.Success())

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=155972&r1=155971&r2=155972&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 Tue May  1 20:11:38 2012
@@ -44,8 +44,30 @@
     m_proc_infos (),
     m_proc_infos_index (0),
     m_lo_port_num (0),
-    m_hi_port_num (0)
-{
+    m_hi_port_num (0),
+    m_ports (),
+    m_mutex (Mutex::eMutexTypeRecursive),
+    m_port_index (0),
+    m_use_port_range (false)
+{
+    // We seldom need to override the port number that the debugserver process
+    // starts with.  We just pass in 0 to let the system choose a random port.
+    // In rare situation where the need arises, use two environment variables
+    // to override.
+    uint16_t lo_port_num = 0;
+    uint16_t hi_port_num = 0;
+    const char *lo_port_c_str = getenv("LLDB_PLATFORM_START_DEBUG_SERVER_LO_PORT");
+    if (lo_port_c_str)
+        lo_port_num = ::atoi(lo_port_c_str);
+    const char *hi_port_c_str = getenv("LLDB_PLATFORM_START_DEBUG_SERVER_HI_PORT");
+    if (hi_port_c_str)
+        hi_port_num = ::atoi(hi_port_c_str);
+    if (lo_port_num && hi_port_num && lo_port_num < hi_port_num)
+    {
+        printf("SetPortRange(%u, %u) called\n", lo_port_num, hi_port_num);
+        SetPortRange(lo_port_num, hi_port_num);
+        m_use_port_range = true;
+    }
 }
 
 //----------------------------------------------------------------------

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=155972&r1=155971&r2=155972&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 Tue May  1 20:11:38 2012
@@ -12,10 +12,11 @@
 
 // C Includes
 // C++ Includes
+#include <vector>
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Host/Mutex.h"
 #include "lldb/Target/Process.h"
-
 #include "GDBRemoteCommunication.h"
 
 class ProcessGDBRemote;
@@ -64,6 +65,7 @@
 
 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;
@@ -73,6 +75,10 @@
     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;
+    bool m_use_port_range;
 
     size_t
     SendUnimplementedResponse (const char *packet);





More information about the lldb-commits mailing list