blob: d8869ad6772e06be8fd73d6de9e04f59d279a905 [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
Andreas Gampe46ee31b2016-12-14 10:11:49 -080023#include "android-base/stringprintf.h"
24
Elliott Hughes07ed66b2012-12-12 18:34:25 -080025#include "base/logging.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080026#include "jdwp/jdwp_priv.h"
Tao Wud0a160d2016-12-13 18:32:17 -080027#include "thread-inl.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080028
Bilyan Borisovbb661c02016-04-04 16:27:32 +010029#ifdef ART_TARGET_ANDROID
Elliott Hughes872d4ec2011-10-21 17:07:15 -070030#include "cutils/sockets.h"
31#endif
32
33/*
34 * The JDWP <-> ADB transport protocol is explained in detail
35 * in system/core/adb/jdwp_service.c. Here's a summary.
36 *
37 * 1/ when the JDWP thread starts, it tries to connect to a Unix
38 * domain stream socket (@jdwp-control) that is opened by the
39 * ADB daemon.
40 *
41 * 2/ it then sends the current process PID as a string of 4 hexadecimal
42 * chars (no terminating zero)
43 *
44 * 3/ then, it uses recvmsg to receive file descriptors from the
45 * daemon. each incoming file descriptor is a pass-through to
46 * a given JDWP debugger, that can be used to read the usual
47 * JDWP-handshake, etc...
48 */
49
Elliott Hughes872d4ec2011-10-21 17:07:15 -070050#define kJdwpControlName "\0jdwp-control"
51#define kJdwpControlNameLen (sizeof(kJdwpControlName)-1)
52
53namespace art {
54
55namespace JDWP {
56
Andreas Gampe46ee31b2016-12-14 10:11:49 -080057using android::base::StringPrintf;
58
Elliott Hughes5d10a872013-04-17 19:26:43 -070059struct JdwpAdbState : public JdwpNetStateBase {
60 public:
Tao Wud0a160d2016-12-13 18:32:17 -080061 explicit JdwpAdbState(JdwpState* state)
62 : JdwpNetStateBase(state),
63 state_lock_("JdwpAdbState lock", kJdwpAdbStateLock) {
Elliott Hughes5d10a872013-04-17 19:26:43 -070064 control_sock_ = -1;
65 shutting_down_ = false;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070066
Elliott Hughes5d10a872013-04-17 19:26:43 -070067 control_addr_.controlAddrUn.sun_family = AF_UNIX;
68 control_addr_len_ = sizeof(control_addr_.controlAddrUn.sun_family) + kJdwpControlNameLen;
69 memcpy(control_addr_.controlAddrUn.sun_path, kJdwpControlName, kJdwpControlNameLen);
70 }
71
72 ~JdwpAdbState() {
73 if (clientSock != -1) {
74 shutdown(clientSock, SHUT_RDWR);
75 close(clientSock);
76 }
77 if (control_sock_ != -1) {
78 shutdown(control_sock_, SHUT_RDWR);
79 close(control_sock_);
80 }
81 }
82
Tao Wud0a160d2016-12-13 18:32:17 -080083 virtual bool Accept() REQUIRES(!state_lock_);
Elliott Hughes5d10a872013-04-17 19:26:43 -070084
85 virtual bool Establish(const JdwpOptions*) {
86 return false;
87 }
88
Tao Wud0a160d2016-12-13 18:32:17 -080089 virtual void Shutdown() REQUIRES(!state_lock_) {
90 int control_sock;
91 int local_clientSock;
92 {
93 MutexLock mu(Thread::Current(), state_lock_);
94 shutting_down_ = true;
95 control_sock = this->control_sock_;
96 local_clientSock = this->clientSock;
97 /* clear these out so it doesn't wake up and try to reuse them */
98 this->control_sock_ = this->clientSock = -1;
99 }
Elliott Hughes5d10a872013-04-17 19:26:43 -0700100
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800101 if (local_clientSock != -1) {
102 shutdown(local_clientSock, SHUT_RDWR);
Elliott Hughes5d10a872013-04-17 19:26:43 -0700103 }
104
105 if (control_sock != -1) {
106 shutdown(control_sock, SHUT_RDWR);
107 }
108
109 WakePipe();
110 }
111
Tao Wud0a160d2016-12-13 18:32:17 -0800112 virtual bool ProcessIncoming() REQUIRES(!state_lock_);
Elliott Hughes5d10a872013-04-17 19:26:43 -0700113
114 private:
Tao Wud0a160d2016-12-13 18:32:17 -0800115 int ReceiveClientFd() REQUIRES(!state_lock_);
Elliott Hughes5d10a872013-04-17 19:26:43 -0700116
Tao Wud0a160d2016-12-13 18:32:17 -0800117 bool IsDown() REQUIRES(!state_lock_) {
118 MutexLock mu(Thread::Current(), state_lock_);
119 return shutting_down_;
120 }
121
122 int ControlSock() REQUIRES(!state_lock_) {
123 MutexLock mu(Thread::Current(), state_lock_);
124 if (shutting_down_) {
125 CHECK_EQ(control_sock_, -1);
126 }
127 return control_sock_;
128 }
129
130 int control_sock_ GUARDED_BY(state_lock_);
131 bool shutting_down_ GUARDED_BY(state_lock_);
132 Mutex state_lock_;
Elliott Hughes5d10a872013-04-17 19:26:43 -0700133
134 socklen_t control_addr_len_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700135 union {
Elliott Hughes5d10a872013-04-17 19:26:43 -0700136 sockaddr_un controlAddrUn;
137 sockaddr controlAddrPlain;
138 } control_addr_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700139};
140
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700141/*
142 * Do initial prep work, e.g. binding to ports and opening files. This
143 * runs in the main thread, before the JDWP thread starts, so it shouldn't
144 * do anything that might block forever.
145 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700146bool InitAdbTransport(JdwpState* state, const JdwpOptions*) {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800147 VLOG(jdwp) << "ADB transport startup";
Elliott Hughes5d10a872013-04-17 19:26:43 -0700148 state->netState = new JdwpAdbState(state);
Sebastien Hertz7d955652014-10-22 10:57:10 +0200149 return (state->netState != nullptr);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700150}
151
152/*
153 * Receive a file descriptor from ADB. The fd can be used to communicate
154 * directly with a debugger or DDMS.
155 *
156 * Returns the file descriptor on success. On failure, returns -1 and
Elliott Hughes5d10a872013-04-17 19:26:43 -0700157 * closes netState->control_sock_.
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700158 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700159int JdwpAdbState::ReceiveClientFd() {
160 char dummy = '!';
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700161 union {
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700162 cmsghdr cm;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700163 char buffer[CMSG_SPACE(sizeof(int))];
164 } cm_un;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700165
Elliott Hughes5d10a872013-04-17 19:26:43 -0700166 iovec iov;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700167 iov.iov_base = &dummy;
168 iov.iov_len = 1;
Elliott Hughes5d10a872013-04-17 19:26:43 -0700169
170 msghdr msg;
Sebastien Hertz7d955652014-10-22 10:57:10 +0200171 msg.msg_name = nullptr;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700172 msg.msg_namelen = 0;
173 msg.msg_iov = &iov;
174 msg.msg_iovlen = 1;
175 msg.msg_flags = 0;
176 msg.msg_control = cm_un.buffer;
177 msg.msg_controllen = sizeof(cm_un.buffer);
178
Elliott Hughes5d10a872013-04-17 19:26:43 -0700179 cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700180 cmsg->cmsg_len = msg.msg_controllen;
181 cmsg->cmsg_level = SOL_SOCKET;
182 cmsg->cmsg_type = SCM_RIGHTS;
Brian Carlstrom2d888622013-07-18 17:02:00 -0700183 (reinterpret_cast<int*>(CMSG_DATA(cmsg)))[0] = -1;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700184
Tao Wud0a160d2016-12-13 18:32:17 -0800185 int rc = TEMP_FAILURE_RETRY(recvmsg(ControlSock(), &msg, 0));
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700186
Elliott Hughes5d10a872013-04-17 19:26:43 -0700187 if (rc <= 0) {
188 if (rc == -1) {
Tao Wud0a160d2016-12-13 18:32:17 -0800189 PLOG(WARNING) << "Receiving file descriptor from ADB failed (socket " << ControlSock() << ")";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700190 }
Tao Wud0a160d2016-12-13 18:32:17 -0800191 MutexLock mu(Thread::Current(), state_lock_);
Elliott Hughes5d10a872013-04-17 19:26:43 -0700192 close(control_sock_);
193 control_sock_ = -1;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700194 return -1;
195 }
196
Brian Carlstrom2d888622013-07-18 17:02:00 -0700197 return (reinterpret_cast<int*>(CMSG_DATA(cmsg)))[0];
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700198}
199
200/*
201 * Block forever, waiting for a debugger to connect to us. Called from the
202 * JDWP thread.
203 *
204 * This needs to un-block and return "false" if the VM is shutting down. It
205 * should return "true" when it successfully accepts a connection.
206 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700207bool JdwpAdbState::Accept() {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700208 int retryCount = 0;
209
210 /* first, ensure that we get a connection to the ADB daemon */
211
Elliott Hughesa21039c2012-06-21 12:09:25 -0700212 retry:
Tao Wud0a160d2016-12-13 18:32:17 -0800213 if (IsDown()) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700214 return false;
215 }
216
Tao Wud0a160d2016-12-13 18:32:17 -0800217 if (ControlSock() == -1) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700218 int sleep_ms = 500;
219 const int sleep_max_ms = 2*1000;
220 char buff[5];
221
Tao Wud0a160d2016-12-13 18:32:17 -0800222 int sock = socket(PF_UNIX, SOCK_STREAM, 0);
223 if (sock < 0) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700224 PLOG(ERROR) << "Could not create ADB control socket";
225 return false;
226 }
Tao Wud0a160d2016-12-13 18:32:17 -0800227 {
228 MutexLock mu(Thread::Current(), state_lock_);
229 control_sock_ = sock;
230 if (shutting_down_) {
231 return false;
232 }
233 if (!MakePipe()) {
234 return false;
235 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700236 }
237
238 snprintf(buff, sizeof(buff), "%04x", getpid());
239 buff[4] = 0;
240
241 for (;;) {
242 /*
243 * If adbd isn't running, because USB debugging was disabled or
244 * perhaps the system is restarting it for "adb root", the
245 * connect() will fail. We loop here forever waiting for it
246 * to come back.
247 *
248 * Waking up and polling every couple of seconds is generally a
249 * bad thing to do, but we only do this if the application is
250 * debuggable *and* adbd isn't running. Still, for the sake
251 * of battery life, we should consider timing out and giving
252 * up after a few minutes in case somebody ships an app with
253 * the debuggable flag set.
254 */
Tao Wud0a160d2016-12-13 18:32:17 -0800255 int ret = connect(ControlSock(), &control_addr_.controlAddrPlain, control_addr_len_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700256 if (!ret) {
Tao Wud0a160d2016-12-13 18:32:17 -0800257 int control_sock = ControlSock();
Bilyan Borisovbb661c02016-04-04 16:27:32 +0100258#ifdef ART_TARGET_ANDROID
Tao Wud0a160d2016-12-13 18:32:17 -0800259 if (control_sock < 0 || !socket_peer_is_trusted(control_sock)) {
260 if (control_sock >= 0 && shutdown(control_sock, SHUT_RDWR)) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700261 PLOG(ERROR) << "trouble shutting down socket";
262 }
263 return false;
264 }
265#endif
266
267 /* now try to send our pid to the ADB daemon */
Tao Wud0a160d2016-12-13 18:32:17 -0800268 ret = TEMP_FAILURE_RETRY(send(control_sock, buff, 4, 0));
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700269 if (ret >= 0) {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800270 VLOG(jdwp) << StringPrintf("PID sent as '%.*s' to ADB", 4, buff);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700271 break;
272 }
273
274 PLOG(ERROR) << "Weird, can't send JDWP process pid to ADB";
275 return false;
276 }
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800277 if (VLOG_IS_ON(jdwp)) {
278 PLOG(ERROR) << "Can't connect to ADB control socket";
279 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700280
Elliott Hughesa21039c2012-06-21 12:09:25 -0700281 usleep(sleep_ms * 1000);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700282
283 sleep_ms += (sleep_ms >> 1);
284 if (sleep_ms > sleep_max_ms) {
285 sleep_ms = sleep_max_ms;
286 }
Tao Wud0a160d2016-12-13 18:32:17 -0800287 if (IsDown()) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700288 return false;
289 }
290 }
291 }
292
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800293 VLOG(jdwp) << "trying to receive file descriptor from ADB";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700294 /* now we can receive a client file descriptor */
Tao Wud0a160d2016-12-13 18:32:17 -0800295 int sock = ReceiveClientFd();
296 {
297 MutexLock mu(Thread::Current(), state_lock_);
298 clientSock = sock;
299 if (shutting_down_) {
300 return false; // suppress logs and additional activity
301 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700302 }
Elliott Hughes5d10a872013-04-17 19:26:43 -0700303 if (clientSock == -1) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700304 if (++retryCount > 5) {
305 LOG(ERROR) << "adb connection max retries exceeded";
306 return false;
307 }
308 goto retry;
309 } else {
Elliott Hughes5d10a872013-04-17 19:26:43 -0700310 VLOG(jdwp) << "received file descriptor " << clientSock << " from ADB";
311 SetAwaitingHandshake(true);
312 input_count_ = 0;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700313 return true;
314 }
315}
316
317/*
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700318 * Process incoming data. If no data is available, this will block until
319 * some arrives.
320 *
321 * If we get a full packet, handle it.
322 *
323 * To take some of the mystery out of life, we want to reject incoming
324 * connections if we already have a debugger attached. If we don't, the
325 * debugger will just mysteriously hang until it times out. We could just
326 * close the listen socket, but there's a good chance we won't be able to
327 * bind to the same port again, which would confuse utilities.
328 *
329 * Returns "false" on error (indicating that the connection has been severed),
330 * "true" if things are still okay.
331 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700332bool JdwpAdbState::ProcessIncoming() {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700333 int readCount;
334
Brian Carlstrom42748892013-07-18 18:04:08 -0700335 CHECK_NE(clientSock, -1);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700336
Elliott Hughes5d10a872013-04-17 19:26:43 -0700337 if (!HaveFullPacket()) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700338 /* read some more, looping until we have data */
339 errno = 0;
340 while (1) {
341 int selCount;
342 fd_set readfds;
343 int maxfd = -1;
344 int fd;
345
346 FD_ZERO(&readfds);
347
348 /* configure fds; note these may get zapped by another thread */
Tao Wud0a160d2016-12-13 18:32:17 -0800349 fd = ControlSock();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700350 if (fd >= 0) {
351 FD_SET(fd, &readfds);
352 if (maxfd < fd) {
353 maxfd = fd;
354 }
355 }
Elliott Hughes5d10a872013-04-17 19:26:43 -0700356 fd = clientSock;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700357 if (fd >= 0) {
358 FD_SET(fd, &readfds);
359 if (maxfd < fd) {
360 maxfd = fd;
361 }
362 }
Elliott Hughes5d10a872013-04-17 19:26:43 -0700363 fd = wake_pipe_[0];
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700364 if (fd >= 0) {
365 FD_SET(fd, &readfds);
366 if (maxfd < fd) {
367 maxfd = fd;
368 }
369 } else {
370 LOG(INFO) << "NOTE: entering select w/o wakepipe";
371 }
372
373 if (maxfd < 0) {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800374 VLOG(jdwp) << "+++ all fds are closed";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700375 return false;
376 }
377
378 /*
379 * Select blocks until it sees activity on the file descriptors.
380 * Closing the local file descriptor does not count as activity,
381 * so we can't rely on that to wake us up (it works for read()
382 * and accept(), but not select()).
383 *
384 * We can do one of three things: (1) send a signal and catch
Elliott Hughes5d10a872013-04-17 19:26:43 -0700385 * EINTR, (2) open an additional fd ("wake pipe") and write to
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700386 * it when it's time to exit, or (3) time out periodically and
387 * re-issue the select. We're currently using #2, as it's more
388 * reliable than #1 and generally better than #3. Wastes two fds.
389 */
Sebastien Hertz7d955652014-10-22 10:57:10 +0200390 selCount = select(maxfd + 1, &readfds, nullptr, nullptr, nullptr);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700391 if (selCount < 0) {
392 if (errno == EINTR) {
393 continue;
394 }
395 PLOG(ERROR) << "select failed";
396 goto fail;
397 }
398
Elliott Hughes5d10a872013-04-17 19:26:43 -0700399 if (wake_pipe_[0] >= 0 && FD_ISSET(wake_pipe_[0], &readfds)) {
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700400 VLOG(jdwp) << "Got wake-up signal, bailing out of select";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700401 goto fail;
402 }
Tao Wud0a160d2016-12-13 18:32:17 -0800403 int control_sock = ControlSock();
404 if (control_sock >= 0 && FD_ISSET(control_sock, &readfds)) {
Elliott Hughes5d10a872013-04-17 19:26:43 -0700405 int sock = ReceiveClientFd();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700406 if (sock >= 0) {
407 LOG(INFO) << "Ignoring second debugger -- accepting and dropping";
408 close(sock);
409 } else {
Tao Wud0a160d2016-12-13 18:32:17 -0800410 CHECK_EQ(ControlSock(), -1);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700411 /*
412 * Remote side most likely went away, so our next read
Elliott Hughes5d10a872013-04-17 19:26:43 -0700413 * on clientSock will fail and throw us out of the loop.
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700414 */
415 }
416 }
Elliott Hughes5d10a872013-04-17 19:26:43 -0700417 if (clientSock >= 0 && FD_ISSET(clientSock, &readfds)) {
418 readCount = read(clientSock, input_buffer_ + input_count_, sizeof(input_buffer_) - input_count_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700419 if (readCount < 0) {
420 /* read failed */
421 if (errno != EINTR) {
422 goto fail;
423 }
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700424 VLOG(jdwp) << "+++ EINTR hit";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700425 return true;
426 } else if (readCount == 0) {
427 /* EOF hit -- far end went away */
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800428 VLOG(jdwp) << "+++ peer disconnected";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700429 goto fail;
430 } else {
431 break;
432 }
433 }
434 }
435
Elliott Hughes5d10a872013-04-17 19:26:43 -0700436 input_count_ += readCount;
437 if (!HaveFullPacket()) {
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700438 return true; /* still not there yet */
439 }
440 }
441
442 /*
443 * Special-case the initial handshake. For some bizarre reason we're
444 * expected to emulate bad tty settings by echoing the request back
445 * exactly as it was sent. Note the handshake is always initiated by
446 * the debugger, no matter who connects to whom.
447 *
448 * Other than this one case, the protocol [claims to be] stateless.
449 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700450 if (IsAwaitingHandshake()) {
451 if (memcmp(input_buffer_, kMagicHandshake, kMagicHandshakeLen) != 0) {
452 LOG(ERROR) << StringPrintf("ERROR: bad handshake '%.14s'", input_buffer_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700453 goto fail;
454 }
455
456 errno = 0;
Elliott Hughes5d10a872013-04-17 19:26:43 -0700457 int cc = TEMP_FAILURE_RETRY(write(clientSock, input_buffer_, kMagicHandshakeLen));
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700458 if (cc != kMagicHandshakeLen) {
459 PLOG(ERROR) << "Failed writing handshake bytes (" << cc << " of " << kMagicHandshakeLen << ")";
460 goto fail;
461 }
462
Elliott Hughes5d10a872013-04-17 19:26:43 -0700463 ConsumeBytes(kMagicHandshakeLen);
464 SetAwaitingHandshake(false);
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800465 VLOG(jdwp) << "+++ handshake complete";
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700466 return true;
467 }
468
469 /*
470 * Handle this packet.
471 */
Elliott Hughes5d10a872013-04-17 19:26:43 -0700472 return state_->HandlePacket();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700473
Elliott Hughesa21039c2012-06-21 12:09:25 -0700474 fail:
Elliott Hughes5d10a872013-04-17 19:26:43 -0700475 Close();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700476 return false;
477}
478
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700479} // namespace JDWP
480
481} // namespace art