diff options
author | Greg Clayton <gclayton@apple.com> | 2012-01-27 00:46:15 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2012-01-27 00:46:15 +0000 |
commit | 23f7793b1305f1e24a38165dae7ee68a28c734e0 (patch) | |
tree | 0eb2a630fb6b19e862b67be198edc03860095ce4 | |
parent | 20275a85770cc9e92bc668296c8a3cfe4010a60e (diff) | |
download | bcm5719-llvm-23f7793b1305f1e24a38165dae7ee68a28c734e0.tar.gz bcm5719-llvm-23f7793b1305f1e24a38165dae7ee68a28c734e0.zip |
<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
.....
llvm-svn: 149103
-rw-r--r-- | lldb/include/lldb/Core/ConnectionFileDescriptor.h | 2 | ||||
-rw-r--r-- | lldb/source/Core/ConnectionFileDescriptor.cpp | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/lldb/include/lldb/Core/ConnectionFileDescriptor.h b/lldb/include/lldb/Core/ConnectionFileDescriptor.h index 44c98eb11da..b2a29d6c6e2 100644 --- a/lldb/include/lldb/Core/ConnectionFileDescriptor.h +++ b/lldb/include/lldb/Core/ConnectionFileDescriptor.h @@ -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 @@ protected: 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); diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp index 6069f8beec5..b349a410b3e 100644 --- a/lldb/source/Core/ConnectionFileDescriptor.cpp +++ b/lldb/source/Core/ConnectionFileDescriptor.cpp @@ -73,7 +73,8 @@ ConnectionFileDescriptor::ConnectionFileDescriptor () : 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 @@ ConnectionFileDescriptor::IsConnected () const 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 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr) 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 @@ ConnectionFileDescriptor::BytesAvailable (uint32_t timeout_usec, Error *error_pt ConnectionStatus ConnectionFileDescriptor::Close (int& fd, Error *error_ptr) { + Mutex::Locker locker (m_mutex); if (error_ptr) error_ptr->Clear(); bool success = true; |