Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1 | /* |
| 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 Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 17 | #include <errno.h> |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 18 | #include <stdlib.h> |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 19 | #include <sys/time.h> |
| 20 | #include <time.h> |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 21 | #include <unistd.h> |
| 22 | |
| 23 | #include "atomic.h" |
| 24 | #include "base/logging.h" |
| 25 | #include "debugger.h" |
| 26 | #include "jdwp/jdwp_priv.h" |
| 27 | #include "scoped_thread_state_change.h" |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | |
| 31 | namespace JDWP { |
| 32 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 33 | static void* StartJdwpThread(void* arg); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * JdwpNetStateBase class implementation |
| 37 | */ |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 38 | JdwpNetStateBase::JdwpNetStateBase(JdwpState* state) |
Mathieu Chartier | 73cca6f | 2013-07-02 17:40:28 -0700 | [diff] [blame] | 39 | : state_(state), socket_lock_("JdwpNetStateBase lock", kJdwpSerialSocketLock) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 40 | clientSock = -1; |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 41 | wake_pipe_[0] = -1; |
| 42 | wake_pipe_[1] = -1; |
| 43 | input_count_ = 0; |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 44 | awaiting_handshake_ = false; |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 47 | JdwpNetStateBase::~JdwpNetStateBase() { |
| 48 | if (wake_pipe_[0] != -1) { |
| 49 | close(wake_pipe_[0]); |
| 50 | wake_pipe_[0] = -1; |
| 51 | } |
| 52 | if (wake_pipe_[1] != -1) { |
| 53 | close(wake_pipe_[1]); |
| 54 | wake_pipe_[1] = -1; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | bool JdwpNetStateBase::MakePipe() { |
| 59 | if (pipe(wake_pipe_) == -1) { |
| 60 | PLOG(ERROR) << "pipe failed"; |
| 61 | return false; |
| 62 | } |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | void JdwpNetStateBase::WakePipe() { |
| 67 | // If we might be sitting in select, kick us loose. |
| 68 | if (wake_pipe_[1] != -1) { |
| 69 | VLOG(jdwp) << "+++ writing to wake pipe"; |
| 70 | TEMP_FAILURE_RETRY(write(wake_pipe_[1], "", 1)); |
| 71 | } |
| 72 | } |
| 73 | |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 74 | void JdwpNetStateBase::ConsumeBytes(size_t count) { |
| 75 | CHECK_GT(count, 0U); |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 76 | CHECK_LE(count, input_count_); |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 77 | |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 78 | if (count == input_count_) { |
| 79 | input_count_ = 0; |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 80 | return; |
| 81 | } |
| 82 | |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 83 | memmove(input_buffer_, input_buffer_ + count, input_count_ - count); |
| 84 | input_count_ -= count; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 87 | bool JdwpNetStateBase::HaveFullPacket() { |
| 88 | if (awaiting_handshake_) { |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 89 | return (input_count_ >= kMagicHandshakeLen); |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 90 | } |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 91 | if (input_count_ < 4) { |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 92 | return false; |
| 93 | } |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 94 | uint32_t length = Get4BE(input_buffer_); |
| 95 | return (input_count_ >= length); |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | bool JdwpNetStateBase::IsAwaitingHandshake() { |
| 99 | return awaiting_handshake_; |
| 100 | } |
| 101 | |
| 102 | void JdwpNetStateBase::SetAwaitingHandshake(bool new_state) { |
| 103 | awaiting_handshake_ = new_state; |
| 104 | } |
| 105 | |
| 106 | bool JdwpNetStateBase::IsConnected() { |
| 107 | return clientSock >= 0; |
| 108 | } |
| 109 | |
| 110 | // Close a connection from a debugger (which may have already dropped us). |
| 111 | // Resets the state so we're ready to receive a new connection. |
| 112 | // Only called from the JDWP thread. |
| 113 | void JdwpNetStateBase::Close() { |
| 114 | if (clientSock < 0) { |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | VLOG(jdwp) << "+++ closing JDWP connection on fd " << clientSock; |
| 119 | |
| 120 | close(clientSock); |
| 121 | clientSock = -1; |
| 122 | } |
| 123 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 124 | /* |
| 125 | * Write a packet. Grabs a mutex to assure atomicity. |
| 126 | */ |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 127 | ssize_t JdwpNetStateBase::WritePacket(ExpandBuf* pReply) { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 128 | MutexLock mu(Thread::Current(), socket_lock_); |
Elliott Hughes | 068193c | 2013-04-15 16:05:28 -0700 | [diff] [blame] | 129 | return TEMP_FAILURE_RETRY(write(clientSock, expandBufGetBuffer(pReply), expandBufGetLength(pReply))); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /* |
| 133 | * Write a buffered packet. Grabs a mutex to assure atomicity. |
| 134 | */ |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 135 | ssize_t JdwpNetStateBase::WriteBufferedPacket(const iovec* iov, int iov_count) { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 136 | MutexLock mu(Thread::Current(), socket_lock_); |
Elliott Hughes | 068193c | 2013-04-15 16:05:28 -0700 | [diff] [blame] | 137 | return TEMP_FAILURE_RETRY(writev(clientSock, iov, iov_count)); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 140 | bool JdwpState::IsConnected() { |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 141 | return netState != NULL && netState->IsConnected(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 144 | void JdwpState::SendBufferedRequest(uint32_t type, const iovec* iov, int iov_count) { |
| 145 | if (netState->clientSock < 0) { |
| 146 | // Can happen with some DDMS events. |
| 147 | VLOG(jdwp) << "Not sending JDWP packet: no debugger attached!"; |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | size_t expected = 0; |
| 152 | for (int i = 0; i < iov_count; ++i) { |
| 153 | expected += iov[i].iov_len; |
| 154 | } |
| 155 | |
| 156 | errno = 0; |
| 157 | ssize_t actual = netState->WriteBufferedPacket(iov, iov_count); |
| 158 | if (static_cast<size_t>(actual) != expected) { |
| 159 | PLOG(ERROR) << StringPrintf("Failed to send JDWP packet %c%c%c%c to debugger (%d of %d)", |
| 160 | static_cast<uint8_t>(type >> 24), |
| 161 | static_cast<uint8_t>(type >> 16), |
| 162 | static_cast<uint8_t>(type >> 8), |
| 163 | static_cast<uint8_t>(type), |
| 164 | actual, expected); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | void JdwpState::SendRequest(ExpandBuf* pReq) { |
| 169 | if (netState->clientSock < 0) { |
| 170 | // Can happen with some DDMS events. |
| 171 | VLOG(jdwp) << "Not sending JDWP packet: no debugger attached!"; |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | errno = 0; |
| 176 | ssize_t actual = netState->WritePacket(pReq); |
| 177 | if (static_cast<size_t>(actual) != expandBufGetLength(pReq)) { |
| 178 | PLOG(ERROR) << StringPrintf("Failed to send JDWP packet to debugger (%d of %d)", |
| 179 | actual, expandBufGetLength(pReq)); |
| 180 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 183 | /* |
| 184 | * Get the next "request" serial number. We use this when sending |
| 185 | * packets to the debugger. |
| 186 | */ |
| 187 | uint32_t JdwpState::NextRequestSerial() { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 188 | MutexLock mu(Thread::Current(), serial_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 189 | return request_serial_++; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 192 | /* |
| 193 | * Get the next "event" serial number. We use this in the response to |
| 194 | * message type EventRequest.Set. |
| 195 | */ |
| 196 | uint32_t JdwpState::NextEventSerial() { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 197 | MutexLock mu(Thread::Current(), serial_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 198 | return event_serial_++; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 201 | JdwpState::JdwpState(const JdwpOptions* options) |
| 202 | : options_(options), |
jeffhao | 0dfbb7e | 2012-11-28 15:26:03 -0800 | [diff] [blame] | 203 | thread_start_lock_("JDWP thread start lock", kJdwpStartLock), |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 204 | thread_start_cond_("JDWP thread start condition variable", thread_start_lock_), |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 205 | pthread_(0), |
| 206 | thread_(NULL), |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 207 | debug_thread_started_(false), |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 208 | debug_thread_id_(0), |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 209 | run(false), |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 210 | netState(NULL), |
jeffhao | 0dfbb7e | 2012-11-28 15:26:03 -0800 | [diff] [blame] | 211 | attach_lock_("JDWP attach lock", kJdwpAttachLock), |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 212 | attach_cond_("JDWP attach condition variable", attach_lock_), |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 213 | last_activity_time_ms_(0), |
Mathieu Chartier | 73cca6f | 2013-07-02 17:40:28 -0700 | [diff] [blame] | 214 | serial_lock_("JDWP serial lock", kJdwpSerialSocketLock), |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 215 | request_serial_(0x10000000), |
| 216 | event_serial_(0x20000000), |
jeffhao | a77f0f6 | 2012-12-05 17:19:31 -0800 | [diff] [blame] | 217 | event_list_lock_("JDWP event list lock", kJdwpEventListLock), |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 218 | event_list_(NULL), |
| 219 | event_list_size_(0), |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 220 | event_thread_lock_("JDWP event thread lock"), |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 221 | event_thread_cond_("JDWP event thread condition variable", event_thread_lock_), |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 222 | event_thread_id_(0), |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 223 | ddm_is_active_(false), |
| 224 | should_exit_(false), |
| 225 | exit_status_(0) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Initialize JDWP. |
| 230 | * |
| 231 | * Does not return until JDWP thread is running, but may return before |
| 232 | * the thread is accepting network connections. |
| 233 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 234 | JdwpState* JdwpState::Create(const JdwpOptions* options) { |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 235 | Thread* self = Thread::Current(); |
| 236 | Locks::mutator_lock_->AssertNotHeld(self); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 237 | UniquePtr<JdwpState> state(new JdwpState(options)); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 238 | switch (options->transport) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 239 | case kJdwpTransportSocket: |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 240 | InitSocketTransport(state.get(), options); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 241 | break; |
| 242 | #ifdef HAVE_ANDROID_OS |
| 243 | case kJdwpTransportAndroidAdb: |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 244 | InitAdbTransport(state.get(), options); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 245 | break; |
| 246 | #endif |
| 247 | default: |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 248 | LOG(FATAL) << "Unknown transport: " << options->transport; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Jeff Hao | add037d | 2013-07-15 14:24:14 -0700 | [diff] [blame^] | 251 | if (!options->suspend) { |
| 252 | /* |
| 253 | * Grab a mutex before starting the thread. This ensures they |
| 254 | * won't signal the cond var before we're waiting. |
| 255 | */ |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 256 | MutexLock thread_start_locker(self, state->thread_start_lock_); |
Jeff Hao | add037d | 2013-07-15 14:24:14 -0700 | [diff] [blame^] | 257 | /* |
| 258 | * We have bound to a port, or are trying to connect outbound to a |
| 259 | * debugger. Create the JDWP thread and let it continue the mission. |
| 260 | */ |
| 261 | CHECK_PTHREAD_CALL(pthread_create, (&state->pthread_, NULL, StartJdwpThread, state.get()), "JDWP thread"); |
| 262 | |
| 263 | /* |
| 264 | * Wait until the thread finishes basic initialization. |
| 265 | * TODO: cond vars should be waited upon in a loop |
| 266 | */ |
| 267 | state->thread_start_cond_.Wait(self); |
| 268 | } else { |
| 269 | { |
| 270 | /* |
| 271 | * Grab a mutex before starting the thread. This ensures they |
| 272 | * won't signal the cond var before we're waiting. |
| 273 | */ |
| 274 | MutexLock thread_start_locker(self, state->thread_start_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 275 | /* |
| 276 | * We have bound to a port, or are trying to connect outbound to a |
| 277 | * debugger. Create the JDWP thread and let it continue the mission. |
| 278 | */ |
| 279 | CHECK_PTHREAD_CALL(pthread_create, (&state->pthread_, NULL, StartJdwpThread, state.get()), "JDWP thread"); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 280 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 281 | /* |
| 282 | * Wait until the thread finishes basic initialization. |
| 283 | * TODO: cond vars should be waited upon in a loop |
| 284 | */ |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 285 | state->thread_start_cond_.Wait(self); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 286 | } |
Jeff Hao | add037d | 2013-07-15 14:24:14 -0700 | [diff] [blame^] | 287 | |
| 288 | /* |
| 289 | * For suspend=y, wait for the debugger to connect to us or for us to |
| 290 | * connect to the debugger. |
| 291 | * |
| 292 | * The JDWP thread will signal us when it connects successfully or |
| 293 | * times out (for timeout=xxx), so we have to check to see what happened |
| 294 | * when we wake up. |
| 295 | */ |
| 296 | { |
| 297 | ScopedThreadStateChange tsc(self, kWaitingForDebuggerToAttach); |
| 298 | MutexLock attach_locker(self, state->attach_lock_); |
| 299 | state->attach_cond_.Wait(self); |
| 300 | } |
| 301 | if (!state->IsActive()) { |
| 302 | LOG(ERROR) << "JDWP connection failed"; |
| 303 | return NULL; |
| 304 | } |
| 305 | |
| 306 | LOG(INFO) << "JDWP connected"; |
| 307 | |
| 308 | /* |
| 309 | * Ordinarily we would pause briefly to allow the debugger to set |
| 310 | * breakpoints and so on, but for "suspend=y" the VM init code will |
| 311 | * pause the VM when it sends the VM_START message. |
| 312 | */ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 315 | return state.release(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Reset all session-related state. There should not be an active connection |
| 320 | * to the client at this point. The rest of the VM still thinks there is |
| 321 | * a debugger attached. |
| 322 | * |
| 323 | * This includes freeing up the debugger event list. |
| 324 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 325 | void JdwpState::ResetState() { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 326 | /* could reset the serial numbers, but no need to */ |
| 327 | |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 328 | UnregisterAll(); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 329 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 330 | MutexLock mu(Thread::Current(), event_list_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 331 | CHECK(event_list_ == NULL); |
| 332 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 333 | |
| 334 | /* |
| 335 | * Should not have one of these in progress. If the debugger went away |
| 336 | * mid-request, though, we could see this. |
| 337 | */ |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 338 | if (event_thread_id_ != 0) { |
Elliott Hughes | 3d30d9b | 2011-12-07 17:35:48 -0800 | [diff] [blame] | 339 | LOG(WARNING) << "Resetting state while event in progress"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 340 | DCHECK(false); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Tell the JDWP thread to shut down. Frees "state". |
| 346 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 347 | JdwpState::~JdwpState() { |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 348 | if (netState != NULL) { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 349 | if (IsConnected()) { |
| 350 | PostVMDeath(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /* |
| 354 | * Close down the network to inspire the thread to halt. |
| 355 | */ |
Elliott Hughes | 0cc1bbd | 2012-01-12 12:27:08 -0800 | [diff] [blame] | 356 | VLOG(jdwp) << "JDWP shutting down net..."; |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 357 | netState->Shutdown(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 358 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 359 | if (debug_thread_started_) { |
| 360 | run = false; |
| 361 | void* threadReturn; |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 362 | if (pthread_join(pthread_, &threadReturn) != 0) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 363 | LOG(WARNING) << "JDWP thread join failed"; |
| 364 | } |
| 365 | } |
| 366 | |
Elliott Hughes | 0cc1bbd | 2012-01-12 12:27:08 -0800 | [diff] [blame] | 367 | VLOG(jdwp) << "JDWP freeing netstate..."; |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 368 | delete netState; |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 369 | netState = NULL; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 370 | } |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 371 | CHECK(netState == NULL); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 372 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 373 | ResetState(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /* |
| 377 | * Are we talking to a debugger? |
| 378 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 379 | bool JdwpState::IsActive() { |
| 380 | return IsConnected(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 383 | // Returns "false" if we encounter a connection-fatal error. |
| 384 | bool JdwpState::HandlePacket() { |
| 385 | JdwpNetStateBase* netStateBase = reinterpret_cast<JdwpNetStateBase*>(netState); |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 386 | JDWP::Request request(netStateBase->input_buffer_, netStateBase->input_count_); |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 387 | |
| 388 | ExpandBuf* pReply = expandBufAlloc(); |
| 389 | ProcessRequest(request, pReply); |
| 390 | ssize_t cc = netStateBase->WritePacket(pReply); |
| 391 | if (cc != (ssize_t) expandBufGetLength(pReply)) { |
| 392 | PLOG(ERROR) << "Failed sending reply to debugger"; |
| 393 | expandBufFree(pReply); |
| 394 | return false; |
| 395 | } |
| 396 | expandBufFree(pReply); |
| 397 | netStateBase->ConsumeBytes(request.GetLength()); |
| 398 | return true; |
| 399 | } |
| 400 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 401 | /* |
| 402 | * Entry point for JDWP thread. The thread was created through the VM |
| 403 | * mechanisms, so there is a java/lang/Thread associated with us. |
| 404 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 405 | static void* StartJdwpThread(void* arg) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 406 | JdwpState* state = reinterpret_cast<JdwpState*>(arg); |
| 407 | CHECK(state != NULL); |
| 408 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 409 | state->Run(); |
| 410 | return NULL; |
| 411 | } |
| 412 | |
| 413 | void JdwpState::Run() { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 414 | Runtime* runtime = Runtime::Current(); |
Mathieu Chartier | 664bebf | 2012-11-12 16:54:11 -0800 | [diff] [blame] | 415 | CHECK(runtime->AttachCurrentThread("JDWP", true, runtime->GetSystemThreadGroup(), |
| 416 | !runtime->IsCompiler())); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 417 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 418 | VLOG(jdwp) << "JDWP: thread running"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 419 | |
| 420 | /* |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 421 | * Finish initializing, then notify the creating thread that |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 422 | * we're running. |
| 423 | */ |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 424 | thread_ = Thread::Current(); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 425 | run = true; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 426 | |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 427 | { |
| 428 | MutexLock locker(thread_, thread_start_lock_); |
| 429 | debug_thread_started_ = true; |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 430 | thread_start_cond_.Broadcast(thread_); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 431 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 432 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 433 | /* set the thread state to kWaitingInMainDebuggerLoop so GCs don't wait for us */ |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 434 | CHECK_EQ(thread_->GetState(), kNative); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 435 | Locks::mutator_lock_->AssertNotHeld(thread_); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 436 | thread_->SetState(kWaitingInMainDebuggerLoop); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 437 | |
| 438 | /* |
| 439 | * Loop forever if we're in server mode, processing connections. In |
| 440 | * non-server mode, we bail out of the thread when the debugger drops |
| 441 | * us. |
| 442 | * |
| 443 | * We broadcast a notification when a debugger attaches, after we |
| 444 | * successfully process the handshake. |
| 445 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 446 | while (run) { |
| 447 | if (options_->server) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 448 | /* |
| 449 | * Block forever, waiting for a connection. To support the |
| 450 | * "timeout=xxx" option we'll need to tweak this. |
| 451 | */ |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 452 | if (!netState->Accept()) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 453 | break; |
| 454 | } |
| 455 | } else { |
| 456 | /* |
| 457 | * If we're not acting as a server, we need to connect out to the |
| 458 | * debugger. To support the "timeout=xxx" option we need to |
| 459 | * have a timeout if the handshake reply isn't received in a |
| 460 | * reasonable amount of time. |
| 461 | */ |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 462 | if (!netState->Establish(options_)) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 463 | /* wake anybody who was waiting for us to succeed */ |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 464 | MutexLock mu(thread_, attach_lock_); |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 465 | attach_cond_.Broadcast(thread_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 466 | break; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | /* prep debug code to handle the new connection */ |
| 471 | Dbg::Connected(); |
| 472 | |
| 473 | /* process requests until the debugger drops */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 474 | bool first = true; |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 475 | while (!Dbg::IsDisposed()) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 476 | { |
| 477 | // sanity check -- shouldn't happen? |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 478 | MutexLock mu(thread_, *Locks::thread_suspend_count_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 479 | CHECK_EQ(thread_->GetState(), kWaitingInMainDebuggerLoop); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 482 | if (!netState->ProcessIncoming()) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 483 | /* blocking read */ |
| 484 | break; |
| 485 | } |
| 486 | |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 487 | if (should_exit_) { |
| 488 | exit(exit_status_); |
| 489 | } |
| 490 | |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 491 | if (first && !netState->IsAwaitingHandshake()) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 492 | /* handshake worked, tell the interpreter that we're active */ |
| 493 | first = false; |
| 494 | |
| 495 | /* set thread ID; requires object registry to be active */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 496 | { |
| 497 | ScopedObjectAccess soa(thread_); |
| 498 | debug_thread_id_ = Dbg::GetThreadSelfId(); |
| 499 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 500 | |
| 501 | /* wake anybody who's waiting for us */ |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 502 | MutexLock mu(thread_, attach_lock_); |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 503 | attach_cond_.Broadcast(thread_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 507 | netState->Close(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 508 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 509 | if (ddm_is_active_) { |
| 510 | ddm_is_active_ = false; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 511 | |
| 512 | /* broadcast the disconnect; must be in RUNNING state */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 513 | thread_->TransitionFromSuspendedToRunnable(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 514 | Dbg::DdmDisconnected(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 515 | thread_->TransitionFromRunnableToSuspended(kWaitingInMainDebuggerLoop); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 518 | { |
| 519 | ScopedObjectAccess soa(thread_); |
Elliott Hughes | 0f82716 | 2013-02-26 12:12:58 -0800 | [diff] [blame] | 520 | |
| 521 | // Release session state, e.g. remove breakpoint instructions. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 522 | ResetState(); |
| 523 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 524 | // Tell the rest of the runtime that the debugger is no longer around. |
| 525 | Dbg::Disconnected(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 526 | |
| 527 | /* if we had threads suspended, resume them now */ |
| 528 | Dbg::UndoDebuggerSuspensions(); |
| 529 | |
| 530 | /* if we connected out, this was a one-shot deal */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 531 | if (!options_->server) { |
| 532 | run = false; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 536 | /* back to native, for thread shutdown */ |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 537 | CHECK_EQ(thread_->GetState(), kWaitingInMainDebuggerLoop); |
| 538 | thread_->SetState(kNative); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 539 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 540 | VLOG(jdwp) << "JDWP: thread detaching and exiting..."; |
Elliott Hughes | 6ba581a | 2011-10-25 11:45:35 -0700 | [diff] [blame] | 541 | runtime->DetachCurrentThread(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 544 | void JdwpState::NotifyDdmsActive() { |
| 545 | if (!ddm_is_active_) { |
| 546 | ddm_is_active_ = true; |
| 547 | Dbg::DdmConnected(); |
| 548 | } |
| 549 | } |
| 550 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 551 | Thread* JdwpState::GetDebugThread() { |
| 552 | return thread_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /* |
| 556 | * Support routines for waitForDebugger(). |
| 557 | * |
| 558 | * We can't have a trivial "waitForDebugger" function that returns the |
| 559 | * instant the debugger connects, because we run the risk of executing code |
| 560 | * before the debugger has had a chance to configure breakpoints or issue |
| 561 | * suspend calls. It would be nice to just sit in the suspended state, but |
| 562 | * most debuggers don't expect any threads to be suspended when they attach. |
| 563 | * |
| 564 | * There's no JDWP event we can post to tell the debugger, "we've stopped, |
| 565 | * and we like it that way". We could send a fake breakpoint, which should |
| 566 | * cause the debugger to immediately send a resume, but the debugger might |
| 567 | * send the resume immediately or might throw an exception of its own upon |
| 568 | * receiving a breakpoint event that it didn't ask for. |
| 569 | * |
| 570 | * What we really want is a "wait until the debugger is done configuring |
| 571 | * stuff" event. We can approximate this with a "wait until the debugger |
| 572 | * has been idle for a brief period". |
| 573 | */ |
| 574 | |
| 575 | /* |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 576 | * Return the time, in milliseconds, since the last debugger activity. |
| 577 | * |
| 578 | * Returns -1 if no debugger is attached, or 0 if we're in the middle of |
| 579 | * processing a debugger request. |
| 580 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 581 | int64_t JdwpState::LastDebuggerActivity() { |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 582 | if (!Dbg::IsDebuggerActive()) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 583 | LOG(DEBUG) << "no active debugger"; |
| 584 | return -1; |
| 585 | } |
| 586 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 587 | int64_t last = QuasiAtomic::Read64(&last_activity_time_ms_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 588 | |
| 589 | /* initializing or in the middle of something? */ |
| 590 | if (last == 0) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 591 | VLOG(jdwp) << "+++ last=busy"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | /* now get the current time */ |
Elliott Hughes | 7162ad9 | 2011-10-27 14:08:42 -0700 | [diff] [blame] | 596 | int64_t now = MilliTime(); |
Elliott Hughes | c3b3e75 | 2012-01-27 13:48:50 -0800 | [diff] [blame] | 597 | CHECK_GE(now, last); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 598 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 599 | VLOG(jdwp) << "+++ debugger interval=" << (now - last); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 600 | return now - last; |
| 601 | } |
| 602 | |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 603 | void JdwpState::ExitAfterReplying(int exit_status) { |
| 604 | LOG(WARNING) << "Debugger told VM to exit with status " << exit_status; |
| 605 | should_exit_ = true; |
| 606 | exit_status_ = exit_status; |
| 607 | } |
| 608 | |
Elliott Hughes | 03181a8 | 2011-11-17 17:22:21 -0800 | [diff] [blame] | 609 | std::ostream& operator<<(std::ostream& os, const JdwpLocation& rhs) { |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 610 | os << "JdwpLocation[" |
Elliott Hughes | a96836a | 2013-01-17 12:27:49 -0800 | [diff] [blame] | 611 | << Dbg::GetClassName(rhs.class_id) << "." << Dbg::GetMethodName(rhs.method_id) |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 612 | << "@" << StringPrintf("%#llx", rhs.dex_pc) << " " << rhs.type_tag << "]"; |
Elliott Hughes | 03181a8 | 2011-11-17 17:22:21 -0800 | [diff] [blame] | 613 | return os; |
| 614 | } |
| 615 | |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 616 | bool operator==(const JdwpLocation& lhs, const JdwpLocation& rhs) { |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 617 | return lhs.dex_pc == rhs.dex_pc && lhs.method_id == rhs.method_id && |
| 618 | lhs.class_id == rhs.class_id && lhs.type_tag == rhs.type_tag; |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | bool operator!=(const JdwpLocation& lhs, const JdwpLocation& rhs) { |
| 622 | return !(lhs == rhs); |
| 623 | } |
| 624 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 625 | } // namespace JDWP |
| 626 | |
| 627 | } // namespace art |