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