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

Jim Ingham jingham at apple.com
Tue Mar 29 16:34:15 PDT 2011


I looked at what claimed to be Linux man pages online, and they claimed to have sranddev, but seeding from time would also be fine, if you want to apply that feel free.  Cryptographic grade random numbers aren't required here, but two lldb's running at the same time shouldn't be trying to use the same port, which is what happens when you try to run lldb on lldb...

BTW, at some point we'll fix this more properly by having lldb open the port, and telling the debugserver it launches to connect back to that.  That way we can avoid these collisions.  But for now anything like this will work.

Thanks,

Jim

On Mar 29, 2011, at 4:20 PM, Stephen Wilson wrote:

> Hi Jim.
> 
> On Tue, Mar 29, 2011 at 09:45:47PM -0000, Jim Ingham wrote:
>> get_random_port ()
>> {
>> +    if (!rand_initialized)
>> +    {
>> +        rand_initialized = true;
>> +        sranddev();
>> +    }
>>     return (rand() % (UINT16_MAX - 1000u)) + 1000u;
>> }
>> 
> 
> Would something like the following address the issue (applied atop your patch)?
> IIRC sranddev() is mostly a BSD'ism, whereas the following should be OK
> in any standard C environment.
> 
> 
> 
> diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
> index b434853..987f246 100644
> --- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
> +++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
> @@ -13,6 +13,7 @@
> #include <stdlib.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> +#include <time.h>
> 
> // C++ Includes
> #include <algorithm>
> @@ -61,8 +62,10 @@ get_random_port ()
> {
>     if (!rand_initialized)
>     {
> +        time_t seed = time(NULL);
> +
>         rand_initialized = true;
> -        sranddev();
> +        srand(seed);
>     }
>     return (rand() % (UINT16_MAX - 1000u)) + 1000u;
> }
> 
> 




More information about the lldb-commits mailing list