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 | |
| 17 | #ifndef ART_JDWP_JDWP_H_ |
| 18 | #define ART_JDWP_JDWP_H_ |
| 19 | |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 20 | #include "base/mutex.h" |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 21 | #include "jdwp/jdwp_bits.h" |
| 22 | #include "jdwp/jdwp_constants.h" |
| 23 | #include "jdwp/jdwp_expand_buf.h" |
| 24 | |
| 25 | #include <pthread.h> |
| 26 | #include <stddef.h> |
| 27 | #include <stdint.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | struct iovec; |
| 31 | |
| 32 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | namespace mirror { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 34 | class AbstractMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | } // namespace mirror |
Ian Rogers | 1b09b09 | 2012-08-20 15:35:52 -0700 | [diff] [blame] | 36 | class Thread; |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 37 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 38 | namespace JDWP { |
| 39 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Fundamental types. |
| 42 | * |
| 43 | * ObjectId and RefTypeId must be the same size. |
| 44 | */ |
| 45 | typedef uint32_t FieldId; /* static or instance field */ |
| 46 | typedef uint32_t MethodId; /* any kind of method, including constructors */ |
| 47 | typedef uint64_t ObjectId; /* any object (threadID, stringID, arrayID, etc) */ |
| 48 | typedef uint64_t RefTypeId; /* like ObjectID, but unique for Class objects */ |
| 49 | typedef uint64_t FrameId; /* short-lived stack frame ID */ |
| 50 | |
Elliott Hughes | a96836a | 2013-01-17 12:27:49 -0800 | [diff] [blame] | 51 | ObjectId ReadObjectId(const uint8_t** pBuf); |
| 52 | |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 53 | static inline void SetFieldId(uint8_t* buf, FieldId val) { return Set4BE(buf, val); } |
| 54 | static inline void SetMethodId(uint8_t* buf, MethodId val) { return Set4BE(buf, val); } |
| 55 | static inline void SetObjectId(uint8_t* buf, ObjectId val) { return Set8BE(buf, val); } |
| 56 | static inline void SetRefTypeId(uint8_t* buf, RefTypeId val) { return Set8BE(buf, val); } |
| 57 | static inline void SetFrameId(uint8_t* buf, FrameId val) { return Set8BE(buf, val); } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 58 | static inline void expandBufAddFieldId(ExpandBuf* pReply, FieldId id) { expandBufAdd4BE(pReply, id); } |
| 59 | static inline void expandBufAddMethodId(ExpandBuf* pReply, MethodId id) { expandBufAdd4BE(pReply, id); } |
| 60 | static inline void expandBufAddObjectId(ExpandBuf* pReply, ObjectId id) { expandBufAdd8BE(pReply, id); } |
| 61 | static inline void expandBufAddRefTypeId(ExpandBuf* pReply, RefTypeId id) { expandBufAdd8BE(pReply, id); } |
| 62 | static inline void expandBufAddFrameId(ExpandBuf* pReply, FrameId id) { expandBufAdd8BE(pReply, id); } |
| 63 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 64 | /* |
| 65 | * Holds a JDWP "location". |
| 66 | */ |
| 67 | struct JdwpLocation { |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 68 | JdwpTypeTag type_tag; |
| 69 | RefTypeId class_id; |
| 70 | MethodId method_id; |
Elliott Hughes | 972a47b | 2012-02-21 18:16:06 -0800 | [diff] [blame] | 71 | uint64_t dex_pc; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 72 | }; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 73 | std::ostream& operator<<(std::ostream& os, const JdwpLocation& rhs) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 74 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 2aa2e39 | 2012-02-17 17:15:43 -0800 | [diff] [blame] | 75 | bool operator==(const JdwpLocation& lhs, const JdwpLocation& rhs); |
| 76 | bool operator!=(const JdwpLocation& lhs, const JdwpLocation& rhs); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * How we talk to the debugger. |
| 80 | */ |
| 81 | enum JdwpTransportType { |
| 82 | kJdwpTransportUnknown = 0, |
Elliott Hughes | 0e57ccb | 2012-04-03 16:04:52 -0700 | [diff] [blame] | 83 | kJdwpTransportSocket, // transport=dt_socket |
| 84 | kJdwpTransportAndroidAdb, // transport=dt_android_adb |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 85 | }; |
| 86 | std::ostream& operator<<(std::ostream& os, const JdwpTransportType& rhs); |
| 87 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 88 | struct JdwpOptions { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 89 | JdwpTransportType transport; |
| 90 | bool server; |
| 91 | bool suspend; |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 92 | std::string host; |
Elliott Hughes | 6d8dd47 | 2012-01-17 18:27:41 -0800 | [diff] [blame] | 93 | uint16_t port; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 96 | struct JdwpEvent; |
| 97 | struct JdwpNetState; |
| 98 | struct JdwpReqHeader; |
| 99 | struct JdwpTransport; |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 100 | struct ModBasket; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 101 | |
| 102 | /* |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 103 | * State for JDWP functions. |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 104 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 105 | struct JdwpState { |
| 106 | /* |
| 107 | * Perform one-time initialization. |
| 108 | * |
| 109 | * Among other things, this binds to a port to listen for a connection from |
| 110 | * the debugger. |
| 111 | * |
| 112 | * Returns a newly-allocated JdwpState struct on success, or NULL on failure. |
| 113 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 114 | static JdwpState* Create(const JdwpOptions* options) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 115 | LOCKS_EXCLUDED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 116 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 117 | ~JdwpState(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 118 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 119 | /* |
| 120 | * Returns "true" if a debugger or DDM is connected. |
| 121 | */ |
| 122 | bool IsActive(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 123 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 124 | /** |
| 125 | * Returns the Thread* for the JDWP daemon thread. |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 126 | */ |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 127 | Thread* GetDebugThread(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 128 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 129 | /* |
| 130 | * Get time, in milliseconds, since the last debugger activity. |
| 131 | */ |
| 132 | int64_t LastDebuggerActivity(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 133 | |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame^] | 134 | void ExitAfterReplying(int exit_status); |
| 135 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 136 | /* |
| 137 | * When we hit a debugger event that requires suspension, it's important |
| 138 | * that we wait for the thread to suspend itself before processing any |
| 139 | * additional requests. (Otherwise, if the debugger immediately sends a |
| 140 | * "resume thread" command, the resume might arrive before the thread has |
| 141 | * suspended itself.) |
| 142 | * |
| 143 | * The thread should call the "set" function before sending the event to |
| 144 | * the debugger. The main JDWP handler loop calls "get" before processing |
| 145 | * an event, and will wait for thread suspension if it's set. Once the |
| 146 | * thread has suspended itself, the JDWP handler calls "clear" and |
| 147 | * continues processing the current event. This works in the suspend-all |
| 148 | * case because the event thread doesn't suspend itself until everything |
| 149 | * else has suspended. |
| 150 | * |
| 151 | * It's possible that multiple threads could encounter thread-suspending |
| 152 | * events at the same time, so we grab a mutex in the "set" call, and |
| 153 | * release it in the "clear" call. |
| 154 | */ |
| 155 | //ObjectId GetWaitForEventThread(); |
| 156 | void SetWaitForEventThread(ObjectId threadId); |
| 157 | void ClearWaitForEventThread(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 158 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 159 | /* |
| 160 | * These notify the debug code that something interesting has happened. This |
| 161 | * could be a thread starting or ending, an exception, or an opportunity |
| 162 | * for a breakpoint. These calls do not mean that an event the debugger |
| 163 | * is interested has happened, just that something has happened that the |
| 164 | * debugger *might* be interested in. |
| 165 | * |
| 166 | * The item of interest may trigger multiple events, some or all of which |
| 167 | * are grouped together in a single response. |
| 168 | * |
| 169 | * The event may cause the current thread or all threads (except the |
| 170 | * JDWP support thread) to be suspended. |
| 171 | */ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 172 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 173 | /* |
| 174 | * The VM has finished initializing. Only called when the debugger is |
| 175 | * connected at the time initialization completes. |
| 176 | */ |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 177 | bool PostVMStart() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 178 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 179 | /* |
| 180 | * A location of interest has been reached. This is used for breakpoints, |
| 181 | * single-stepping, and method entry/exit. (JDWP requires that these four |
| 182 | * events are grouped together in a single response.) |
| 183 | * |
| 184 | * In some cases "*pLoc" will just have a method and class name, e.g. when |
| 185 | * issuing a MethodEntry on a native method. |
| 186 | * |
| 187 | * "eventFlags" indicates the types of events that have occurred. |
| 188 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 189 | bool PostLocationEvent(const JdwpLocation* pLoc, ObjectId thisPtr, int eventFlags) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 190 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 191 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 192 | /* |
| 193 | * An exception has been thrown. |
| 194 | * |
| 195 | * Pass in a zeroed-out "*pCatchLoc" if the exception wasn't caught. |
| 196 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 197 | bool PostException(const JdwpLocation* pThrowLoc, ObjectId excepId, RefTypeId excepClassId, |
| 198 | const JdwpLocation* pCatchLoc, ObjectId thisPtr) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 199 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 200 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 201 | /* |
| 202 | * A thread has started or stopped. |
| 203 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 204 | bool PostThreadChange(ObjectId threadId, bool start) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 205 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 206 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 207 | /* |
| 208 | * Class has been prepared. |
| 209 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 210 | bool PostClassPrepare(JdwpTypeTag tag, RefTypeId refTypeId, const std::string& signature, |
| 211 | int status) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 212 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 213 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 214 | /* |
| 215 | * The VM is about to stop. |
| 216 | */ |
| 217 | bool PostVMDeath(); |
| 218 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 219 | // Called if/when we realize we're talking to DDMS. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 220 | void NotifyDdmsActive() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 221 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 222 | /* |
| 223 | * Send up a chunk of DDM data. |
| 224 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 225 | void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 226 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 227 | |
| 228 | /* |
| 229 | * Process a request from the debugger. |
| 230 | * |
| 231 | * "buf" points past the header, to the content of the message. "dataLen" |
| 232 | * can therefore be zero. |
| 233 | */ |
| 234 | void ProcessRequest(const JdwpReqHeader* pHeader, const uint8_t* buf, int dataLen, ExpandBuf* pReply); |
| 235 | |
| 236 | /* |
| 237 | * Send an event, formatted into "pReq", to the debugger. |
| 238 | * |
| 239 | * (Messages are sent asynchronously, and do not receive a reply.) |
| 240 | */ |
| 241 | bool SendRequest(ExpandBuf* pReq); |
| 242 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 243 | void ResetState() |
| 244 | LOCKS_EXCLUDED(event_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 245 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 246 | |
| 247 | /* atomic ops to get next serial number */ |
| 248 | uint32_t NextRequestSerial(); |
| 249 | uint32_t NextEventSerial(); |
| 250 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 251 | void Run() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 252 | LOCKS_EXCLUDED(Locks::mutator_lock_, |
| 253 | Locks::thread_suspend_count_lock_); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 254 | |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 255 | /* |
| 256 | * Register an event by adding it to the event list. |
| 257 | * |
| 258 | * "*pEvent" must be storage allocated with jdwpEventAlloc(). The caller |
| 259 | * may discard its pointer after calling this. |
| 260 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 261 | JdwpError RegisterEvent(JdwpEvent* pEvent) |
| 262 | LOCKS_EXCLUDED(event_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 263 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 264 | |
| 265 | /* |
| 266 | * Unregister an event, given the requestId. |
| 267 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 268 | void UnregisterEventById(uint32_t requestId) |
| 269 | LOCKS_EXCLUDED(event_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 270 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * Unregister all events. |
| 274 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 275 | void UnregisterAll() |
| 276 | LOCKS_EXCLUDED(event_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 277 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 278 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 279 | private: |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 280 | explicit JdwpState(const JdwpOptions* options); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 281 | bool InvokeInProgress(); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 282 | bool IsConnected(); |
jeffhao | a77f0f6 | 2012-12-05 17:19:31 -0800 | [diff] [blame] | 283 | void SuspendByPolicy(JdwpSuspendPolicy suspend_policy, JDWP::ObjectId thread_self_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 284 | LOCKS_EXCLUDED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 285 | void SendRequestAndPossiblySuspend(ExpandBuf* pReq, JdwpSuspendPolicy suspend_policy, |
| 286 | ObjectId threadId) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 287 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 288 | void CleanupMatchList(JdwpEvent** match_list, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 289 | int match_count) |
| 290 | EXCLUSIVE_LOCKS_REQUIRED(event_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 291 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 292 | void EventFinish(ExpandBuf* pReq); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 293 | void FindMatchingEvents(JdwpEventKind eventKind, |
| 294 | ModBasket* basket, |
| 295 | JdwpEvent** match_list, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 296 | int* pMatchCount) |
| 297 | EXCLUSIVE_LOCKS_REQUIRED(event_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 298 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 299 | void UnregisterEvent(JdwpEvent* pEvent) |
| 300 | EXCLUSIVE_LOCKS_REQUIRED(event_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 301 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 302 | |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 303 | public: // TODO: fix privacy |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 304 | const JdwpOptions* options_; |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 305 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 306 | private: |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 307 | /* wait for creation of the JDWP thread */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 308 | Mutex thread_start_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 309 | ConditionVariable thread_start_cond_ GUARDED_BY(thread_start_lock_); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 310 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 311 | pthread_t pthread_; |
| 312 | Thread* thread_; |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 313 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 314 | volatile int32_t debug_thread_started_ GUARDED_BY(thread_start_lock_); |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 315 | ObjectId debug_thread_id_; |
| 316 | |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 317 | private: |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 318 | bool run; |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 319 | const JdwpTransport* transport_; |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 320 | |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 321 | public: // TODO: fix privacy |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 322 | JdwpNetState* netState; |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 323 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 324 | private: |
| 325 | // For wait-for-debugger. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 326 | Mutex attach_lock_ ACQUIRED_AFTER(thread_start_lock_); |
| 327 | ConditionVariable attach_cond_ GUARDED_BY(attach_lock_); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 328 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 329 | // Time of last debugger activity, in milliseconds. |
| 330 | int64_t last_activity_time_ms_; |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 331 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 332 | // Global counters and a mutex to protect them. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 333 | Mutex serial_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 334 | uint32_t request_serial_ GUARDED_BY(serial_lock_); |
| 335 | uint32_t event_serial_ GUARDED_BY(serial_lock_); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 336 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 337 | // Linked list of events requested by the debugger (breakpoints, class prep, etc). |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 338 | Mutex event_list_lock_; |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 339 | JdwpEvent* event_list_ GUARDED_BY(event_list_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 340 | int event_list_size_ GUARDED_BY(event_list_lock_); // Number of elements in event_list_. |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 341 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 342 | // Used to synchronize suspension of the event thread (to avoid receiving "resume" |
| 343 | // events before the thread has finished suspending itself). |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 344 | Mutex event_thread_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 345 | ConditionVariable event_thread_cond_ GUARDED_BY(event_thread_lock_); |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 346 | ObjectId event_thread_id_; |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 347 | |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 348 | bool ddm_is_active_; |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame^] | 349 | |
| 350 | bool should_exit_; |
| 351 | int exit_status_; |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 352 | }; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 353 | |
| 354 | } // namespace JDWP |
| 355 | |
| 356 | } // namespace art |
| 357 | |
| 358 | #endif // ART_JDWP_JDWP_H_ |