OSDN Git Service

Work around a dalvik JDWP/GC deadlock.
[android-x86/dalvik.git] / vm / jdwp / JdwpAdb.cpp
index f0156bd..8fb5391 100644 (file)
@@ -115,7 +115,7 @@ static bool startup(struct JdwpState* state, const JdwpStartupParams* pParams)
 {
     JdwpNetState*  netState;
 
-    LOGV("ADB transport startup");
+    ALOGV("ADB transport startup");
 
     state->netState = netState = new JdwpNetState;
     if (netState == NULL)
@@ -165,10 +165,8 @@ static int  receiveClientFd(JdwpNetState*  netState)
 
     if (ret <= 0) {
         if (ret < 0) {
-            LOGW("receiving file descriptor from ADB failed (socket %d): %s",
+            ALOGW("receiving file descriptor from ADB failed (socket %d): %s",
                  netState->controlSock, strerror(errno));
-        } else {
-            LOGD("adbd disconnected");
         }
         close(netState->controlSock);
         netState->controlSock = -1;
@@ -203,13 +201,13 @@ retry:
 
         netState->controlSock = socket(PF_UNIX, SOCK_STREAM, 0);
         if (netState->controlSock < 0) {
-            LOGE("Could not create ADB control socket:%s",
+            ALOGE("Could not create ADB control socket:%s",
                  strerror(errno));
             return false;
         }
 
         if (pipe(netState->wakeFds) < 0) {
-            LOGE("pipe failed");
+            ALOGE("pipe failed");
             return false;
         }
 
@@ -236,7 +234,7 @@ retry:
             if (!ret) {
                 if (!socket_peer_is_trusted(netState->controlSock)) {
                     if (shutdown(netState->controlSock, SHUT_RDWR)) {
-                        LOGE("trouble shutting down socket: %s", strerror(errno));
+                        ALOGE("trouble shutting down socket: %s", strerror(errno));
                     }
                     return false;
                 }
@@ -247,15 +245,15 @@ retry:
                 } while (ret < 0 && errno == EINTR);
 
                 if (ret >= 0) {
-                    LOGV("PID sent as '%.*s' to ADB", 4, buff);
+                    ALOGV("PID sent as '%.*s' to ADB", 4, buff);
                     break;
                 }
 
-                LOGE("Weird, can't send JDWP process pid to ADB: %s",
+                ALOGE("Weird, can't send JDWP process pid to ADB: %s",
                      strerror(errno));
                 return false;
             }
-            LOGV("Can't connect to ADB control socket:%s",
+            ALOGV("Can't connect to ADB control socket:%s",
                  strerror(errno));
 
             usleep( sleep_ms*1000 );
@@ -269,7 +267,7 @@ retry:
         }
     }
 
-    LOGV("trying to receive file descriptor from ADB");
+    ALOGV("trying to receive file descriptor from ADB");
     /* now we can receive a client file descriptor */
     netState->clientSock = receiveClientFd(netState);
     if (netState->shuttingDown)
@@ -277,12 +275,12 @@ retry:
 
     if (netState->clientSock < 0) {
         if (++retryCount > 5) {
-            LOGE("adb connection max retries exceeded");
+            ALOGE("adb connection max retries exceeded");
             return false;
         }
         goto retry;
     } else {
-        LOGV("received file descriptor %d from ADB", netState->clientSock);
+        ALOGV("received file descriptor %d from ADB", netState->clientSock);
         netState->awaitingHandshake = 1;
         netState->inputCount = 0;
         return true;
@@ -311,7 +309,7 @@ static void closeConnection(struct JdwpState* state)
     if (netState->clientSock < 0)
         return;
 
-    LOGV("+++ closed JDWP <-> ADB connection");
+    ALOGV("+++ closed JDWP <-> ADB connection");
 
     close(netState->clientSock);
     netState->clientSock = -1;
@@ -346,8 +344,8 @@ static void adbStateShutdown(struct JdwpNetState* netState)
     }
 
     if (netState->wakeFds[1] >= 0) {
-        LOGV("+++ writing to wakePipe");
-        write(netState->wakeFds[1], "", 1);
+        ALOGV("+++ writing to wakePipe");
+        TEMP_FAILURE_RETRY(write(netState->wakeFds[1], "", 1));
     }
 }
 
@@ -465,20 +463,20 @@ static bool handlePacket(JdwpState* state)
             ssize_t cc = netState->writePacket(pReply);
 
             if (cc != (ssize_t) expandBufGetLength(pReply)) {
-                LOGE("Failed sending reply to debugger: %s", strerror(errno));
+                ALOGE("Failed sending reply to debugger: %s", strerror(errno));
                 expandBufFree(pReply);
                 return false;
             }
         } else {
-            LOGW("No reply created for set=%d cmd=%d", cmdSet, cmd);
+            ALOGW("No reply created for set=%d cmd=%d", cmdSet, cmd);
         }
         expandBufFree(pReply);
     } else {
-        LOGV("reply?!");
+        ALOGV("reply?!");
         assert(false);
     }
 
-    LOGV("----------");
+    ALOGV("----------");
 
     consumeBytes(netState, length);
     return true;
@@ -536,11 +534,11 @@ static bool processIncoming(JdwpState* state)
                 if (maxfd < fd)
                     maxfd = fd;
             } else {
-                LOGI("NOTE: entering select w/o wakepipe");
+                ALOGI("NOTE: entering select w/o wakepipe");
             }
 
             if (maxfd < 0) {
-                LOGV("+++ all fds are closed");
+                ALOGV("+++ all fds are closed");
                 return false;
             }
 
@@ -560,14 +558,14 @@ static bool processIncoming(JdwpState* state)
             if (selCount < 0) {
                 if (errno == EINTR)
                     continue;
-                LOGE("select failed: %s", strerror(errno));
+                ALOGE("select failed: %s", strerror(errno));
                 goto fail;
             }
 
             if (netState->wakeFds[0] >= 0 &&
                 FD_ISSET(netState->wakeFds[0], &readfds))
             {
-                LOGD("Got wake-up signal, bailing out of select");
+                ALOGD("Got wake-up signal, bailing out of select");
                 goto fail;
             }
             if (netState->controlSock >= 0 &&
@@ -575,7 +573,7 @@ static bool processIncoming(JdwpState* state)
             {
                 int  sock = receiveClientFd(netState);
                 if (sock >= 0) {
-                    LOGI("Ignoring second debugger -- accepting and dropping");
+                    ALOGI("Ignoring second debugger -- accepting and dropping");
                     close(sock);
                 } else {
                     assert(netState->controlSock < 0);
@@ -596,11 +594,11 @@ static bool processIncoming(JdwpState* state)
                     /* read failed */
                     if (errno != EINTR)
                         goto fail;
-                    LOGD("+++ EINTR hit");
+                    ALOGD("+++ EINTR hit");
                     return true;
                 } else if (readCount == 0) {
                     /* EOF hit -- far end went away */
-                    LOGV("+++ peer disconnected");
+                    ALOGV("+++ peer disconnected");
                     goto fail;
                 } else
                     break;
@@ -626,22 +624,22 @@ static bool processIncoming(JdwpState* state)
         if (memcmp(netState->inputBuffer,
                 kMagicHandshake, kMagicHandshakeLen) != 0)
         {
-            LOGE("ERROR: bad handshake '%.14s'", netState->inputBuffer);
+            ALOGE("ERROR: bad handshake '%.14s'", netState->inputBuffer);
             goto fail;
         }
 
         errno = 0;
-        cc = write(netState->clientSock, netState->inputBuffer,
-                kMagicHandshakeLen);
+        cc = TEMP_FAILURE_RETRY(write(netState->clientSock, netState->inputBuffer,
+                                      kMagicHandshakeLen));
         if (cc != kMagicHandshakeLen) {
-            LOGE("Failed writing handshake bytes: %s (%d of %d)",
+            ALOGE("Failed writing handshake bytes: %s (%d of %d)",
                 strerror(errno), cc, (int) kMagicHandshakeLen);
             goto fail;
         }
 
         consumeBytes(netState, kMagicHandshakeLen);
         netState->awaitingHandshake = false;
-        LOGV("+++ handshake complete");
+        ALOGV("+++ handshake complete");
         return true;
     }
 
@@ -669,7 +667,7 @@ static bool sendRequest(JdwpState* state, ExpandBuf* pReq)
 
     if (netState->clientSock < 0) {
         /* can happen with some DDMS events */
-        LOGV("NOT sending request -- no debugger is attached");
+        ALOGV("NOT sending request -- no debugger is attached");
         return false;
     }
 
@@ -678,7 +676,7 @@ static bool sendRequest(JdwpState* state, ExpandBuf* pReq)
     ssize_t cc = netState->writePacket(pReq);
 
     if (cc != (ssize_t) expandBufGetLength(pReq)) {
-        LOGE("Failed sending req to debugger: %s (%d of %d)",
+        ALOGE("Failed sending req to debugger: %s (%d of %d)",
             strerror(errno), (int) cc, (int) expandBufGetLength(pReq));
         return false;
     }
@@ -701,7 +699,7 @@ static bool sendBufferedRequest(JdwpState* state, const struct iovec* iov,
 
     if (netState->clientSock < 0) {
         /* can happen with some DDMS events */
-        LOGV("NOT sending request -- no debugger is attached");
+        ALOGV("NOT sending request -- no debugger is attached");
         return false;
     }
 
@@ -713,7 +711,7 @@ static bool sendBufferedRequest(JdwpState* state, const struct iovec* iov,
     ssize_t actual = netState->writeBufferedPacket(iov, iovcnt);
 
     if ((size_t)actual != expected) {
-        LOGE("Failed sending b-req to debugger: %s (%d of %zu)",
+        ALOGE("Failed sending b-req to debugger: %s (%d of %zu)",
             strerror(errno), (int) actual, expected);
         return false;
     }