[Lldb-commits] [lldb] r149103 - in /lldb/trunk: include/lldb/Core/ConnectionFileDescriptor.h source/Core/ConnectionFileDescriptor.cpp
Greg Clayton
gclayton at apple.com
Thu Jan 26 16:46:15 PST 2012
Author: gclayton
Date: Thu Jan 26 18:46:15 2012
New Revision: 149103
URL: http://llvm.org/viewvc/llvm-project?rev=149103&view=rev
Log:
<rdar://problem/10760649>
Fixed another double file descriptor close issue that could occur when destroying a ProcessGDBRemote() object. There was a race which was detected by our fd_interposing library:
error: /Applications/Xcode.app/Contents/MacOS/Xcode (pid=55222): close (fd=60) resulted in EBADF:
0 libFDInterposing.dylib 0x00000001082be8ca close$__interposed__ + 666
1 LLDB 0x00000001194fde91 lldb_private::ConnectionFileDescriptor::Close(int&, lldb_private::Error*) + 97
2 LLDB 0x00000001194fddcd lldb_private::ConnectionFileDescriptor::Disconnect(lldb_private::Error*) + 143
3 LLDB 0x00000001194fe249 lldb_private::ConnectionFileDescriptor::Read(void*, unsigned long, unsigned int, lldb::ConnectionStatus&, lldb_private::Error*) + 835
4 LLDB 0x00000001194fc320 lldb_private::Communication::Read(void*, unsigned long, unsigned int, lldb::ConnectionStatus&, lldb_private::Error*) + 634
5 LLDB 0x000000011959c7f4 GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock(StringExtractorGDBRemote&, unsigned int) + 228
6 LLDB 0x000000011959c6b5 GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSeconds(StringExtractorGDBRemote&, unsigned int) + 49
7 LLDB 0x0000000119629a71 GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse(ProcessGDBRemote*, char const*, unsigned long, StringExtractorGDBRemote&) + 509
8 LLDB 0x00000001195a4076 ProcessGDBRemote::AsyncThread(void*) + 514
9 LLDB 0x0000000119568094 ThreadCreateTrampoline(void*) + 91
10 libsystem_c.dylib 0x00007fff8ca028bf _pthread_start + 335
11 libsystem_c.dylib 0x00007fff8ca05b75 thread_start + 13
fd=60 was previously closed with this event:
pid=55222: close (fd=60) => 0
0 libFDInterposing.dylib 0x00000001082be870 close$__interposed__ + 576
1 LLDB 0x00000001194fde91 lldb_private::ConnectionFileDescriptor::Close(int&, lldb_private::Error*) + 97
2 LLDB 0x00000001194fddcd lldb_private::ConnectionFileDescriptor::Disconnect(lldb_private::Error*) + 143
3 LLDB 0x00000001194fbf00 lldb_private::Communication::Disconnect(lldb_private::Error*) + 92
4 LLDB 0x00000001195a2a77 ProcessGDBRemote::StopAsyncThread() + 89
5 LLDB 0x00000001195a2bf6 ProcessGDBRemote::DoDestroy() + 310
6 LLDB 0x00000001195f938d lldb_private::Process::Destroy() + 85
7 LLDB 0x0000000118819b48 lldb::SBProcess::Kill() + 72
8 DebuggerLLDB 0x0000000117264358 DBGLLDBSessionThread(void*) + 4450
9 LLDB 0x0000000119568094 ThreadCreateTrampoline(void*) + 91
10 libsystem_c.dylib 0x00007fff8ca028bf _pthread_start + 335
11 libsystem_c.dylib 0x00007fff8ca05b75 thread_start + 13
fd=60 was created with this event:
pid=55222: socket (domain = 2, type = 1, protocol = 6) => fd=60
0 libFDInterposing.dylib 0x00000001082bc968 socket$__interposed__ + 600
1 LLDB 0x00000001194fd75f lldb_private::ConnectionFileDescriptor::ConnectTCP(char const*, lldb_private::Error*) + 179
.....
Modified:
lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h
lldb/trunk/source/Core/ConnectionFileDescriptor.cpp
Modified: lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h?rev=149103&r1=149102&r2=149103&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h (original)
+++ lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h Thu Jan 26 18:46:15 2012
@@ -19,6 +19,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Connection.h"
+#include "lldb/Host/Mutex.h"
#include "lldb/Host/SocketAddress.h"
namespace lldb_private {
@@ -104,6 +105,7 @@
SocketAddress m_udp_send_sockaddr;
bool m_should_close_fd; // True if this class should close the file descriptor when it goes away.
uint32_t m_socket_timeout_usec;
+ Mutex m_mutex;
static in_port_t
GetSocketPort (int fd);
Modified: lldb/trunk/source/Core/ConnectionFileDescriptor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConnectionFileDescriptor.cpp?rev=149103&r1=149102&r2=149103&view=diff
==============================================================================
--- lldb/trunk/source/Core/ConnectionFileDescriptor.cpp (original)
+++ lldb/trunk/source/Core/ConnectionFileDescriptor.cpp Thu Jan 26 18:46:15 2012
@@ -73,7 +73,8 @@
m_fd_recv_type (eFDTypeFile),
m_udp_send_sockaddr (),
m_should_close_fd (false),
- m_socket_timeout_usec(0)
+ m_socket_timeout_usec(0),
+ m_mutex (Mutex::eMutexTypeRecursive)
{
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT));
if (log)
@@ -113,6 +114,7 @@
ConnectionStatus
ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr)
{
+ Mutex::Locker locker (m_mutex);
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION));
if (log)
log->Printf ("%p ConnectionFileDescriptor::Connect (url = '%s')", this, s);
@@ -232,6 +234,7 @@
ConnectionStatus
ConnectionFileDescriptor::Disconnect (Error *error_ptr)
{
+ Mutex::Locker locker (m_mutex);
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION));
if (log)
log->Printf ("%p ConnectionFileDescriptor::Disconnect ()", this);
@@ -599,6 +602,7 @@
ConnectionStatus
ConnectionFileDescriptor::Close (int& fd, Error *error_ptr)
{
+ Mutex::Locker locker (m_mutex);
if (error_ptr)
error_ptr->Clear();
bool success = true;
More information about the lldb-commits
mailing list