[Lldb-commits] [lldb] r160514 - /lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Sean Callanan scallanan at apple.com
Thu Jul 19 11:07:36 PDT 2012


Author: spyffe
Date: Thu Jul 19 13:07:36 2012
New Revision: 160514

URL: http://llvm.org/viewvc/llvm-project?rev=160514&view=rev
Log:
Changed ProcessGDBRemote to avoid the reserved
port range.  Also added a comment indicating that
more work is needed.

<rdar://problem/11580051>

Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=160514&r1=160513&r2=160514&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Thu Jul 19 13:07:36 2012
@@ -11,6 +11,7 @@
 #include <errno.h>
 #include <spawn.h>
 #include <stdlib.h>
+#include <netinet/in.h>
 #include <sys/mman.h>       // for mmap
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -80,6 +81,18 @@
 
 static bool rand_initialized = false;
 
+// TODO Randomly assigning a port is unsafe.  We should get an unused
+// ephemeral port from the kernel and make sure we reserve it before passing
+// it to debugserver.
+
+#if defined (__APPLE__)
+#define LOW_PORT    (IPPORT_RESERVED)
+#define HIGH_PORT   (IPPORT_HIFIRSTAUTO)
+#else
+#define LOW_PORT    (1024u)
+#define HIGH_PORT   (49151u)
+#endif
+
 static inline uint16_t
 get_random_port ()
 {
@@ -90,7 +103,7 @@
         rand_initialized = true;
         srand(seed);
     }
-    return (rand() % (UINT16_MAX - 1000u)) + 1000u;
+    return (rand() % (HIGH_PORT - LOW_PORT)) + LOW_PORT;
 }
 
 





More information about the lldb-commits mailing list