blob: 16e80503592d426a013342850c64e2d7dd360172 [file] [log] [blame]
Elliott Hughes872d4ec2011-10-21 17:07:15 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Elliott Hughes872d4ec2011-10-21 17:07:15 -070017#include <errno.h>
18#include <stdio.h>
19#include <sys/socket.h>
20#include <sys/un.h>
21#include <unistd.h>
22
Elliott Hughes07ed66b2012-12-12 18:34:25 -080023#include "base/logging.h"
Elliott Hughese222ee02012-12-13 14:41:43 -080024#include "base/stringprintf.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080025#include "jdwp/jdwp_priv.h"
Tao Wud0a160d2016-12-13 18:32:17 -080026#include "thread-inl.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080027
Bilyan Borisovbb661c02016-04-04 16:27:32 +010028#ifdef ART_TARGET_ANDROID
Elliott Hughes872d4ec2011-10-21 17:07:15 -070029#include "cutils/sockets.h"
30#endif
31
32/*
33 * The JDWP <-> ADB transport protocol is explained in detail
34 * in system/core/adb/jdwp_service.c. Here's a summary.
35 *
36 * 1/ when the JDWP thread starts, it tries to connect to a Unix
37 * domain stream socket (@jdwp-control) that is opened by the
38 * ADB daemon.
39 *
40 * 2/ it then sends the current process PID as a string of 4 hexadecimal
41 * chars (no terminating zero)
42 *
43 * 3/ then, it uses recvmsg to receive file descriptors from the
44 * daemon. each incoming file descriptor is a pass-through to
45 * a given JDWP debugger, that can be used to read the usual
46 * JDWP-handshake, etc...
47 */
48
Elliott Hughes872d4ec2011-10-21 17:07:15 -070049#define kJdwpControlName "\0jdwp-control"
50#define kJdwpControlNameLen (sizeof(kJdwpControlName)-1)
51
52namespace art {
53
54namespace JDWP {
55
Elliott Hughes5d10a872013-04-17 19:26:43 -070056struct JdwpAdbState : public JdwpNetStateBase {
57 public:
Tao Wud0a160d2016-12-13 18:32:17 -080058 explicit JdwpAdbState(JdwpState* state)
59 : JdwpNetStateBase(state),
60 state_lock_("JdwpAdbState lock", kJdwpAdbStateLock) {
Elliott Hughes5d10a872013-04-17 19:26:43 -070061 control_sock_ = -1;
62 shutting_down_ = false;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070063
Elliott Hughes5d10a872013-04-17 19:26:43 -070064 control_addr_.controlAddrUn.sun_family = AF_UNIX;
65 control_addr_len_ = sizeof(control_addr_.controlAddrUn.sun_family) + kJdwpControlNameLen;
66 memcpy(control_addr_.controlAddrUn.sun_path, kJdwpControlName, kJdwpControlNameLen);
67 }
68
69 ~JdwpAdbState() {
70 if (clientSock != -1) {
71 shutdown(clientSock, SHUT_RDWR);
72 close(clientSock);
73 }
74 if (control_sock_ != -1) {
75 shutdown(control_sock_, SHUT_RDWR);
76 close(control_sock_);
77 }
78 }
79
Tao Wud0a160d2016-12-13 18:32:17 -080080 virtual bool Accept() REQUIRES(!state_lock_);
Elliott Hughes5d10a872013-04-17 19:26:43 -070081
82 virtual bool Establish(const JdwpOptions*) {
83 return false;
84 }
85
Tao Wud0a160d2016-12-13 18:32:17 -080086 virtual void Shutdown() REQUIRES(!state_lock_) {
87 int control_sock;
88 int local_clientSock;
89 {
90 MutexLock mu(Thread::Current(), state_lock_);
91 shutting_down_ = true;
92 control_sock = this->control_sock_;
93 local_clientSock = this->clientSock;
94 /* clear these out so it doesn't wake up and try to reuse them */
95 this->control_sock_ = this->clientSock = -1;
96 }
Elliott Hughes5d10a872013-04-17 19:26:43 -070097
Andreas Gampe277ccbd2014-11-03 21:36:10 -080098 if (local_clientSock != -1) {
99 shutdown(local_clientSock, SHUT_RDWR);
Elliott Hughes5d10a872013-04-17 19:26:43 -0700100 }
101
102 if (control_sock != -1) {
103 shutdown(control_sock, SHUT_RDWR);
104 }
105
106 WakePipe();
107 }
108
Tao Wud0a160d2016-12-13 18:32:17 -0800109 virtual bool ProcessIncoming() REQUIRES(!state_lock_);
Elliott Hughes5d10a872013-04-17 19:26:43 -0700110
111 private:
Tao Wud0a160d2016-12-13 18:32:17 -0800112 int ReceiveClientFd() REQUIRES(!state_lock_);
Elliott Hughes5d10a872013-04-17 19:26:43 -0700113
Tao Wud0a160d2016-12-13 18:32:17 -0800114 bool IsDown() REQUIRES(!state_lock_) {
115 MutexLock mu(Thread::Current(), state_lock_);
116 return shutting_down_;
117 }
118
119 int ControlSock() REQUIRES(!state_lock_) {
120 MutexLock mu(Thread::Current(), state_lock_);
121 if (shutting_down_) {
122 CHECK_EQ(control_sock_, -1);
123 }
124 return control_sock_;
125 }
126
127 int control_sock_ GUARDED_BY(state_lock_);
128 bool shutting_down_ GUARDED_BY(state_lock_);
129 Mutex state_lock_;
Elliott Hughes5d10a872013-04-17 19:26:43 -0700130
131 socklen_t control_addr_len_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700132 union {
Elliott Hughes5d10a872013-04-17 19:26:43 -0700133 sockaddr_un controlAddrUn;
134 sockaddr controlAddrPlain;
135 } control_addr_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700136};
137
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700138/*
139 * Do initial prep work, e.g. binding to ports and opening files. This
140 * runs in the main thread, before the JDWP thread starts, so it shouldn't
141 * do anything that might block forever.
142 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700143bool InitAdbTransport(JdwpState* state, const JdwpOptions*) {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800144 VLOG(jdwp) << "ADB transport startup";
Elliott Hughes5d10a872013-04-17 19:26:43 -0700145 state->netState = new JdwpAdbState(state);
Sebastien Hertz7d955652014-10-22 10:57:10 +0200146 return (state->netState != nullptr);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700147}
148
149/*
150 * Receive a file descriptor from ADB. The fd can be used to communicate
151 * directly with a debugger or DDMS.
152 *
153 * Returns the file descriptor on success. On failure, returns -1 and
Elliott Hughes5d10a872013-04-17 19:26:43 -0700154 * closes netState->control_sock_.
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700155 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700156int JdwpAdbState::ReceiveClientFd() {
157 char dummy = '!';
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700158 union {
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700159 cmsghdr cm;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700160 char buffer[CMSG_SPACE(sizeof(int))];
161 } cm_un;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700162
Elliott Hughes5d10a872013-04-17 19:26:43 -0700163 iovec iov;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700164 iov.iov_base = &dummy;
165 iov.iov_len = 1;
Elliott Hughes5d10a872013-04-17 19:26:43 -0700166
167 msghdr msg;
Sebastien Hertz7d955652014-10-22 10:57:10 +0200168 msg.msg_name = nullptr;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700169 msg.msg_namelen = 0;
170 msg.msg_iov = &iov;
171 msg.msg_iovlen = 1;
172 msg.msg_flags = 0;
173 msg.msg_control = cm_un.buffer;
174 msg.msg_controllen = sizeof(cm_un.buffer);
175
Elliott Hughes5d10a872013-04-17 19:26:43 -0700176 cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700177 cmsg->cmsg_len = msg.msg_controllen;
178 cmsg->cmsg_level = SOL_SOCKET;
179 cmsg->cmsg_type = SCM_RIGHTS;
Brian Carlstrom2d888622013-07-18 17:02:00 -0700180 (reinterpret_cast<int*>(CMSG_DATA(cmsg)))[0] = -1;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700181
Tao Wud0a160d2016-12-13 18:32:17 -0800182 int rc = TEMP_FAILURE_RETRY(recvmsg(ControlSock(), &msg, 0));
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700183
Elliott Hughes5d10a872013-04-17 19:26:43 -0700184 if (rc <= 0) {
185 if (rc == -1) {
Tao Wud0a160d2016-12-13 18:32:17 -0800186 PLOG(WARNING) << "Receiving file descriptor from ADB failed (socket " << ControlSock() << ")";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700187 }
Tao Wud0a160d2016-12-13 18:32:17 -0800188 MutexLock mu(Thread::Current(), state_lock_);
Elliott Hughes5d10a872013-04-17 19:26:43 -0700189 close(control_sock_);
190 control_sock_ = -1;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700191 return -1;
192 }
193
Brian Carlstrom2d888622013-07-18 17:02:00 -0700194 return (reinterpret_cast<int*>(CMSG_DATA(cmsg)))[0];
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700195}
196
197/*
198 * Block forever, waiting for a debugger to connect to us. Called from the
199 * JDWP thread.
200 *
201 * This needs to un-block and return "false" if the VM is shutting down. It
202 * should return "true" when it successfully accepts a connection.
203 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700204bool JdwpAdbState::Accept() {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700205 int retryCount = 0;
206
207 /* first, ensure that we get a connection to the ADB daemon */
208
Elliott Hughesa21039c2012-06-21 12:09:25 -0700209 retry:
Tao Wud0a160d2016-12-13 18:32:17 -0800210 if (IsDown()) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700211 return false;
212 }
213
Tao Wud0a160d2016-12-13 18:32:17 -0800214 if (ControlSock() == -1) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700215 int sleep_ms = 500;
216 const int sleep_max_ms = 2*1000;
217 char buff[5];
218
Tao Wud0a160d2016-12-13 18:32:17 -0800219 int sock = socket(PF_UNIX, SOCK_STREAM, 0);
220 if (sock < 0) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700221 PLOG(ERROR) << "Could not create ADB control socket";
222 return false;
223 }
Tao Wud0a160d2016-12-13 18:32:17 -0800224 {
225 MutexLock mu(Thread::Current(), state_lock_);
226 control_sock_ = sock;
227 if (shutting_down_) {
228 return false;
229 }
230 if (!MakePipe()) {
231 return false;
232 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700233 }
234
235 snprintf(buff, sizeof(buff), "%04x", getpid());
236 buff[4] = 0;
237
238 for (;;) {
239 /*
240 * If adbd isn't running, because USB debugging was disabled or
241 * perhaps the system is restarting it for "adb root", the
242 * connect() will fail. We loop here forever waiting for it
243 * to come back.
244 *
245 * Waking up and polling every couple of seconds is generally a
246 * bad thing to do, but we only do this if the application is
247 * debuggable *and* adbd isn't running. Still, for the sake
248 * of battery life, we should consider timing out and giving
249 * up after a few minutes in case somebody ships an app with
250 * the debuggable flag set.
251 */
Tao Wud0a160d2016-12-13 18:32:17 -0800252 int ret = connect(ControlSock(), &control_addr_.controlAddrPlain, control_addr_len_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700253 if (!ret) {
Tao Wud0a160d2016-12-13 18:32:17 -0800254 int control_sock = ControlSock();
Bilyan Borisovbb661c02016-04-04 16:27:32 +0100255#ifdef ART_TARGET_ANDROID
Tao Wud0a160d2016-12-13 18:32:17 -0800256 if (control_sock < 0 || !socket_peer_is_trusted(control_sock)) {
257 if (control_sock >= 0 && shutdown(control_sock, SHUT_RDWR)) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700258 PLOG(ERROR) << "trouble shutting down socket";
259 }
260 return false;
261 }
262#endif
263
264 /* now try to send our pid to the ADB daemon */
Tao Wud0a160d2016-12-13 18:32:17 -0800265 ret = TEMP_FAILURE_RETRY(send(control_sock, buff, 4, 0));
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700266 if (ret >= 0) {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800267 VLOG(jdwp) << StringPrintf("PID sent as '%.*s' to ADB", 4, buff);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700268 break;
269 }
270
271 PLOG(ERROR) << "Weird, can't send JDWP process pid to ADB";
272 return false;
273 }
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800274 if (VLOG_IS_ON(jdwp)) {
275 PLOG(ERROR) << "Can't connect to ADB control socket";
276 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700277
Elliott Hughesa21039c2012-06-21 12:09:25 -0700278 usleep(sleep_ms * 1000);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700279
280 sleep_ms += (sleep_ms >> 1);
281 if (sleep_ms > sleep_max_ms) {
282 sleep_ms = sleep_max_ms;
283 }
Tao Wud0a160d2016-12-13 18:32:17 -0800284 if (IsDown()) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700285 return false;
286 }
287 }
288 }
289
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800290 VLOG(jdwp) << "trying to receive file descriptor from ADB";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700291 /* now we can receive a client file descriptor */
Tao Wud0a160d2016-12-13 18:32:17 -0800292 int sock = ReceiveClientFd();
293 {
294 MutexLock mu(Thread::Current(), state_lock_);
295 clientSock = sock;
296 if (shutting_down_) {
297 return false; // suppress logs and additional activity
298 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700299 }
Elliott Hughes5d10a872013-04-17 19:26:43 -0700300 if (clientSock == -1) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700301 if (++retryCount > 5) {
302 LOG(ERROR) << "adb connection max retries exceeded";
303 return false;
304 }
305 goto retry;
306 } else {
Elliott Hughes5d10a872013-04-17 19:26:43 -0700307 VLOG(jdwp) << "received file descriptor " << clientSock << " from ADB";
308 SetAwaitingHandshake(true);
309 input_count_ = 0;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700310 return true;
311 }
312}
313
314/*
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700315 * Process incoming data. If no data is available, this will block until
316 * some arrives.
317 *
318 * If we get a full packet, handle it.
319 *
320 * To take some of the mystery out of life, we want to reject incoming
321 * connections if we already have a debugger attached. If we don't, the
322 * debugger will just mysteriously hang until it times out. We could just
323 * close the listen socket, but there's a good chance we won't be able to
324 * bind to the same port again, which would confuse utilities.
325 *
326 * Returns "false" on error (indicating that the connection has been severed),
327 * "true" if things are still okay.
328 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700329bool JdwpAdbState::ProcessIncoming() {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700330 int readCount;
331
Brian Carlstrom42748892013-07-18 18:04:08 -0700332 CHECK_NE(clientSock, -1);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700333
Elliott Hughes5d10a872013-04-17 19:26:43 -0700334 if (!HaveFullPacket()) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700335 /* read some more, looping until we have data */
336 errno = 0;
337 while (1) {
338 int selCount;
339 fd_set readfds;
340 int maxfd = -1;
341 int fd;
342
343 FD_ZERO(&readfds);
344
345 /* configure fds; note these may get zapped by another thread */
Tao Wud0a160d2016-12-13 18:32:17 -0800346 fd = ControlSock();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700347 if (fd >= 0) {
348 FD_SET(fd, &readfds);
349 if (maxfd < fd) {
350 maxfd = fd;
351 }
352 }
Elliott Hughes5d10a872013-04-17 19:26:43 -0700353 fd = clientSock;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700354 if (fd >= 0) {
355 FD_SET(fd, &readfds);
356 if (maxfd < fd) {
357 maxfd = fd;
358 }
359 }
Elliott Hughes5d10a872013-04-17 19:26:43 -0700360 fd = wake_pipe_[0];
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700361 if (fd >= 0) {
362 FD_SET(fd, &readfds);
363 if (maxfd < fd) {
364 maxfd = fd;
365 }
366 } else {
367 LOG(INFO) << "NOTE: entering select w/o wakepipe";
368 }
369
370 if (maxfd < 0) {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800371 VLOG(jdwp) << "+++ all fds are closed";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700372 return false;
373 }
374
375 /*
376 * Select blocks until it sees activity on the file descriptors.
377 * Closing the local file descriptor does not count as activity,
378 * so we can't rely on that to wake us up (it works for read()
379 * and accept(), but not select()).
380 *
381 * We can do one of three things: (1) send a signal and catch
Elliott Hughes5d10a872013-04-17 19:26:43 -0700382 * EINTR, (2) open an additional fd ("wake pipe") and write to
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700383 * it when it's time to exit, or (3) time out periodically and
384 * re-issue the select. We're currently using #2, as it's more
385 * reliable than #1 and generally better than #3. Wastes two fds.
386 */
Sebastien Hertz7d955652014-10-22 10:57:10 +0200387 selCount = select(maxfd + 1, &readfds, nullptr, nullptr, nullptr);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700388 if (selCount < 0) {
389 if (errno == EINTR) {
390 continue;
391 }
392 PLOG(ERROR) << "select failed";
393 goto fail;
394 }
395
Elliott Hughes5d10a872013-04-17 19:26:43 -0700396 if (wake_pipe_[0] >= 0 && FD_ISSET(wake_pipe_[0], &readfds)) {
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700397 VLOG(jdwp) << "Got wake-up signal, bailing out of select";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700398 goto fail;
399 }
Tao Wud0a160d2016-12-13 18:32:17 -0800400 int control_sock = ControlSock();
401 if (control_sock >= 0 && FD_ISSET(control_sock, &readfds)) {
Elliott Hughes5d10a872013-04-17 19:26:43 -0700402 int sock = ReceiveClientFd();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700403 if (sock >= 0) {
404 LOG(INFO) << "Ignoring second debugger -- accepting and dropping";
405 close(sock);
406 } else {
Tao Wud0a160d2016-12-13 18:32:17 -0800407 CHECK_EQ(ControlSock(), -1);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700408 /*
409 * Remote side most likely went away, so our next read
Elliott Hughes5d10a872013-04-17 19:26:43 -0700410 * on clientSock will fail and throw us out of the loop.
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700411 */
412 }
413 }
Elliott Hughes5d10a872013-04-17 19:26:43 -0700414 if (clientSock >= 0 && FD_ISSET(clientSock, &readfds)) {
415 readCount = read(clientSock, input_buffer_ + input_count_, sizeof(input_buffer_) - input_count_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700416 if (readCount < 0) {
417 /* read failed */
418 if (errno != EINTR) {
419 goto fail;
420 }
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700421 VLOG(jdwp) << "+++ EINTR hit";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700422 return true;
423 } else if (readCount == 0) {
424 /* EOF hit -- far end went away */
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800425 VLOG(jdwp) << "+++ peer disconnected";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700426 goto fail;
427 } else {
428 break;
429 }
430 }
431 }
432
Elliott Hughes5d10a872013-04-17 19:26:43 -0700433 input_count_ += readCount;
434 if (!HaveFullPacket()) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700435 return true; /* still not there yet */
436 }
437 }
438
439 /*
440 * Special-case the initial handshake. For some bizarre reason we're
441 * expected to emulate bad tty settings by echoing the request back
442 * exactly as it was sent. Note the handshake is always initiated by
443 * the debugger, no matter who connects to whom.
444 *
445 * Other than this one case, the protocol [claims to be] stateless.
446 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700447 if (IsAwaitingHandshake()) {
448 if (memcmp(input_buffer_, kMagicHandshake, kMagicHandshakeLen) != 0) {
449 LOG(ERROR) << StringPrintf("ERROR: bad handshake '%.14s'", input_buffer_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700450 goto fail;
451 }
452
453 errno = 0;
Elliott Hughes5d10a872013-04-17 19:26:43 -0700454 int cc = TEMP_FAILURE_RETRY(write(clientSock, input_buffer_, kMagicHandshakeLen));
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700455 if (cc != kMagicHandshakeLen) {
456 PLOG(ERROR) << "Failed writing handshake bytes (" << cc << " of " << kMagicHandshakeLen << ")";
457 goto fail;
458 }
459
Elliott Hughes5d10a872013-04-17 19:26:43 -0700460 ConsumeBytes(kMagicHandshakeLen);
461 SetAwaitingHandshake(false);
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800462 VLOG(jdwp) << "+++ handshake complete";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700463 return true;
464 }
465
466 /*
467 * Handle this packet.
468 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700469 return state_->HandlePacket();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700470
Elliott Hughesa21039c2012-06-21 12:09:25 -0700471 fail:
Elliott Hughes5d10a872013-04-17 19:26:43 -0700472 Close();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700473 return false;
474}
475
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700476} // namespace JDWP
477
478} // namespace art