blob: fdbdfeb3b194a8345428943be884f9f24e3c365d [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_JDWP_JDWP_H_
18#define ART_RUNTIME_JDWP_JDWP_H_
Elliott Hughes872d4ec2011-10-21 17:07:15 -070019
Ian Rogersef7d42f2014-01-06 12:55:46 -080020#include "atomic.h"
Elliott Hughes76b61672012-12-12 17:47:30 -080021#include "base/mutex.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070022#include "jdwp/jdwp_bits.h"
23#include "jdwp/jdwp_constants.h"
24#include "jdwp/jdwp_expand_buf.h"
25
26#include <pthread.h>
27#include <stddef.h>
28#include <stdint.h>
29#include <string.h>
30
31struct iovec;
32
33namespace art {
Jeff Hao579b0242013-11-18 13:16:49 -080034 union JValue;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035namespace mirror {
Brian Carlstromea46f952013-07-30 01:26:50 -070036 class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037} // namespace mirror
Ian Rogers1b09b092012-08-20 15:35:52 -070038class Thread;
Elliott Hughes475fc232011-10-25 15:00:35 -070039
Elliott Hughes872d4ec2011-10-21 17:07:15 -070040namespace JDWP {
41
Elliott Hughes872d4ec2011-10-21 17:07:15 -070042/*
43 * Fundamental types.
44 *
45 * ObjectId and RefTypeId must be the same size.
46 */
47typedef uint32_t FieldId; /* static or instance field */
48typedef uint32_t MethodId; /* any kind of method, including constructors */
49typedef uint64_t ObjectId; /* any object (threadID, stringID, arrayID, etc) */
50typedef uint64_t RefTypeId; /* like ObjectID, but unique for Class objects */
51typedef uint64_t FrameId; /* short-lived stack frame ID */
52
Elliott Hughesa96836a2013-01-17 12:27:49 -080053ObjectId ReadObjectId(const uint8_t** pBuf);
54
Elliott Hughesf7c3b662011-10-27 12:04:56 -070055static inline void SetFieldId(uint8_t* buf, FieldId val) { return Set4BE(buf, val); }
56static inline void SetMethodId(uint8_t* buf, MethodId val) { return Set4BE(buf, val); }
57static inline void SetObjectId(uint8_t* buf, ObjectId val) { return Set8BE(buf, val); }
58static inline void SetRefTypeId(uint8_t* buf, RefTypeId val) { return Set8BE(buf, val); }
59static inline void SetFrameId(uint8_t* buf, FrameId val) { return Set8BE(buf, val); }
Elliott Hughes872d4ec2011-10-21 17:07:15 -070060static inline void expandBufAddFieldId(ExpandBuf* pReply, FieldId id) { expandBufAdd4BE(pReply, id); }
61static inline void expandBufAddMethodId(ExpandBuf* pReply, MethodId id) { expandBufAdd4BE(pReply, id); }
62static inline void expandBufAddObjectId(ExpandBuf* pReply, ObjectId id) { expandBufAdd8BE(pReply, id); }
63static inline void expandBufAddRefTypeId(ExpandBuf* pReply, RefTypeId id) { expandBufAdd8BE(pReply, id); }
64static inline void expandBufAddFrameId(ExpandBuf* pReply, FrameId id) { expandBufAdd8BE(pReply, id); }
65
Elliott Hughes872d4ec2011-10-21 17:07:15 -070066/*
67 * Holds a JDWP "location".
68 */
69struct JdwpLocation {
Elliott Hughes74847412012-06-20 18:10:21 -070070 JdwpTypeTag type_tag;
71 RefTypeId class_id;
72 MethodId method_id;
Elliott Hughes972a47b2012-02-21 18:16:06 -080073 uint64_t dex_pc;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070074};
Ian Rogers00f7d0e2012-07-19 15:28:27 -070075std::ostream& operator<<(std::ostream& os, const JdwpLocation& rhs)
Ian Rogersb726dcb2012-09-05 08:57:23 -070076 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2aa2e392012-02-17 17:15:43 -080077bool operator==(const JdwpLocation& lhs, const JdwpLocation& rhs);
78bool operator!=(const JdwpLocation& lhs, const JdwpLocation& rhs);
Elliott Hughes872d4ec2011-10-21 17:07:15 -070079
80/*
81 * How we talk to the debugger.
82 */
83enum JdwpTransportType {
84 kJdwpTransportUnknown = 0,
Elliott Hughes0e57ccb2012-04-03 16:04:52 -070085 kJdwpTransportSocket, // transport=dt_socket
86 kJdwpTransportAndroidAdb, // transport=dt_android_adb
Elliott Hughes872d4ec2011-10-21 17:07:15 -070087};
88std::ostream& operator<<(std::ostream& os, const JdwpTransportType& rhs);
89
Elliott Hughes376a7a02011-10-24 18:35:55 -070090struct JdwpOptions {
Elliott Hughes872d4ec2011-10-21 17:07:15 -070091 JdwpTransportType transport;
92 bool server;
93 bool suspend;
Elliott Hughesd1cc8362011-10-24 16:58:50 -070094 std::string host;
Elliott Hughes6d8dd472012-01-17 18:27:41 -080095 uint16_t port;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070096};
97
Elliott Hughes376a7a02011-10-24 18:35:55 -070098struct JdwpEvent;
Ian Rogersb48b9eb2014-02-28 16:20:21 -080099class JdwpNetStateBase;
Elliott Hughes761928d2011-11-16 18:33:03 -0800100struct ModBasket;
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800101class Request;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700102
103/*
Elliott Hughes376a7a02011-10-24 18:35:55 -0700104 * State for JDWP functions.
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700105 */
Elliott Hughes376a7a02011-10-24 18:35:55 -0700106struct JdwpState {
107 /*
108 * Perform one-time initialization.
109 *
110 * Among other things, this binds to a port to listen for a connection from
111 * the debugger.
112 *
113 * Returns a newly-allocated JdwpState struct on success, or NULL on failure.
114 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700115 static JdwpState* Create(const JdwpOptions* options)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700116 LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700117
Elliott Hughes376a7a02011-10-24 18:35:55 -0700118 ~JdwpState();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700119
Elliott Hughes376a7a02011-10-24 18:35:55 -0700120 /*
121 * Returns "true" if a debugger or DDM is connected.
122 */
123 bool IsActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700124
Elliott Hughes475fc232011-10-25 15:00:35 -0700125 /**
126 * Returns the Thread* for the JDWP daemon thread.
Elliott Hughes376a7a02011-10-24 18:35:55 -0700127 */
Elliott Hughes475fc232011-10-25 15:00:35 -0700128 Thread* GetDebugThread();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700129
Elliott Hughes376a7a02011-10-24 18:35:55 -0700130 /*
131 * Get time, in milliseconds, since the last debugger activity.
132 */
133 int64_t LastDebuggerActivity();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700134
Elliott Hughes64f574f2013-02-20 14:57:12 -0800135 void ExitAfterReplying(int exit_status);
136
Elliott Hughes376a7a02011-10-24 18:35:55 -0700137 /*
138 * When we hit a debugger event that requires suspension, it's important
139 * that we wait for the thread to suspend itself before processing any
140 * additional requests. (Otherwise, if the debugger immediately sends a
141 * "resume thread" command, the resume might arrive before the thread has
142 * suspended itself.)
143 *
144 * The thread should call the "set" function before sending the event to
145 * the debugger. The main JDWP handler loop calls "get" before processing
146 * an event, and will wait for thread suspension if it's set. Once the
147 * thread has suspended itself, the JDWP handler calls "clear" and
148 * continues processing the current event. This works in the suspend-all
149 * case because the event thread doesn't suspend itself until everything
150 * else has suspended.
151 *
152 * It's possible that multiple threads could encounter thread-suspending
153 * events at the same time, so we grab a mutex in the "set" call, and
154 * release it in the "clear" call.
155 */
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700156 // ObjectId GetWaitForEventThread();
Sebastien Hertz400a3a92014-02-24 14:56:21 +0100157 void SetWaitForEventThread(ObjectId threadId)
158 LOCKS_EXCLUDED(event_thread_lock_, process_request_lock_);
159 void ClearWaitForEventThread() LOCKS_EXCLUDED(event_thread_lock);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700160
Elliott Hughes376a7a02011-10-24 18:35:55 -0700161 /*
162 * These notify the debug code that something interesting has happened. This
163 * could be a thread starting or ending, an exception, or an opportunity
164 * for a breakpoint. These calls do not mean that an event the debugger
165 * is interested has happened, just that something has happened that the
166 * debugger *might* be interested in.
167 *
168 * The item of interest may trigger multiple events, some or all of which
169 * are grouped together in a single response.
170 *
171 * The event may cause the current thread or all threads (except the
172 * JDWP support thread) to be suspended.
173 */
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700174
Elliott Hughes376a7a02011-10-24 18:35:55 -0700175 /*
176 * The VM has finished initializing. Only called when the debugger is
177 * connected at the time initialization completes.
178 */
Ian Rogersb726dcb2012-09-05 08:57:23 -0700179 bool PostVMStart() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700180
Elliott Hughes376a7a02011-10-24 18:35:55 -0700181 /*
182 * A location of interest has been reached. This is used for breakpoints,
183 * single-stepping, and method entry/exit. (JDWP requires that these four
184 * events are grouped together in a single response.)
185 *
186 * In some cases "*pLoc" will just have a method and class name, e.g. when
187 * issuing a MethodEntry on a native method.
188 *
189 * "eventFlags" indicates the types of events that have occurred.
Jeff Hao579b0242013-11-18 13:16:49 -0800190 *
191 * "returnValue" is non-null for MethodExit events only.
Elliott Hughes376a7a02011-10-24 18:35:55 -0700192 */
Jeff Hao579b0242013-11-18 13:16:49 -0800193 bool PostLocationEvent(const JdwpLocation* pLoc, ObjectId thisPtr, int eventFlags,
194 const JValue* returnValue)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700195 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700196
Elliott Hughes376a7a02011-10-24 18:35:55 -0700197 /*
198 * An exception has been thrown.
199 *
200 * Pass in a zeroed-out "*pCatchLoc" if the exception wasn't caught.
201 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700202 bool PostException(const JdwpLocation* pThrowLoc, ObjectId excepId, RefTypeId excepClassId,
203 const JdwpLocation* pCatchLoc, ObjectId thisPtr)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700204 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700205
Elliott Hughes376a7a02011-10-24 18:35:55 -0700206 /*
207 * A thread has started or stopped.
208 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700209 bool PostThreadChange(ObjectId threadId, bool start)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700211
Elliott Hughes376a7a02011-10-24 18:35:55 -0700212 /*
213 * Class has been prepared.
214 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700215 bool PostClassPrepare(JdwpTypeTag tag, RefTypeId refTypeId, const std::string& signature,
216 int status)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700217 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700218
Elliott Hughes376a7a02011-10-24 18:35:55 -0700219 /*
220 * The VM is about to stop.
221 */
222 bool PostVMDeath();
223
Elliott Hughesa21039c2012-06-21 12:09:25 -0700224 // Called if/when we realize we're talking to DDMS.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700225 void NotifyDdmsActive() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa21039c2012-06-21 12:09:25 -0700226
Elliott Hughes376a7a02011-10-24 18:35:55 -0700227 /*
228 * Send up a chunk of DDM data.
229 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700230 void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700231 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes376a7a02011-10-24 18:35:55 -0700232
Elliott Hughescb693062013-02-21 09:48:08 -0800233 bool HandlePacket();
Elliott Hughes376a7a02011-10-24 18:35:55 -0700234
Elliott Hughes68a5e3c2013-04-17 17:13:35 -0700235 void SendRequest(ExpandBuf* pReq);
Elliott Hughes376a7a02011-10-24 18:35:55 -0700236
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700237 void ResetState()
238 LOCKS_EXCLUDED(event_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes376a7a02011-10-24 18:35:55 -0700240
241 /* atomic ops to get next serial number */
242 uint32_t NextRequestSerial();
243 uint32_t NextEventSerial();
244
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700245 void Run()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700246 LOCKS_EXCLUDED(Locks::mutator_lock_,
247 Locks::thread_suspend_count_lock_);
Elliott Hughes376a7a02011-10-24 18:35:55 -0700248
Elliott Hughes761928d2011-11-16 18:33:03 -0800249 /*
250 * Register an event by adding it to the event list.
251 *
252 * "*pEvent" must be storage allocated with jdwpEventAlloc(). The caller
253 * may discard its pointer after calling this.
254 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700255 JdwpError RegisterEvent(JdwpEvent* pEvent)
256 LOCKS_EXCLUDED(event_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700257 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes761928d2011-11-16 18:33:03 -0800258
259 /*
260 * Unregister an event, given the requestId.
261 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700262 void UnregisterEventById(uint32_t requestId)
263 LOCKS_EXCLUDED(event_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700264 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes761928d2011-11-16 18:33:03 -0800265
266 /*
267 * Unregister all events.
268 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700269 void UnregisterAll()
270 LOCKS_EXCLUDED(event_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700271 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes761928d2011-11-16 18:33:03 -0800272
Elliott Hughes376a7a02011-10-24 18:35:55 -0700273 private:
Elliott Hughesba8eee12012-01-24 20:25:24 -0800274 explicit JdwpState(const JdwpOptions* options);
Elliott Hughescb693062013-02-21 09:48:08 -0800275 void ProcessRequest(Request& request, ExpandBuf* pReply);
Elliott Hughes761928d2011-11-16 18:33:03 -0800276 bool InvokeInProgress();
Elliott Hughes376a7a02011-10-24 18:35:55 -0700277 bool IsConnected();
jeffhaoa77f0f62012-12-05 17:19:31 -0800278 void SuspendByPolicy(JdwpSuspendPolicy suspend_policy, JDWP::ObjectId thread_self_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700279 LOCKS_EXCLUDED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700280 void SendRequestAndPossiblySuspend(ExpandBuf* pReq, JdwpSuspendPolicy suspend_policy,
281 ObjectId threadId)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700283 void CleanupMatchList(JdwpEvent** match_list,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700284 int match_count)
285 EXCLUSIVE_LOCKS_REQUIRED(event_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700286 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes761928d2011-11-16 18:33:03 -0800287 void EventFinish(ExpandBuf* pReq);
Elliott Hughesf8349362012-06-18 15:00:06 -0700288 void FindMatchingEvents(JdwpEventKind eventKind,
289 ModBasket* basket,
290 JdwpEvent** match_list,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700291 int* pMatchCount)
292 EXCLUSIVE_LOCKS_REQUIRED(event_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700293 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700294 void UnregisterEvent(JdwpEvent* pEvent)
295 EXCLUSIVE_LOCKS_REQUIRED(event_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromf5293522013-07-19 00:24:00 -0700297 void SendBufferedRequest(uint32_t type, const std::vector<iovec>& iov);
Elliott Hughes376a7a02011-10-24 18:35:55 -0700298
Sebastien Hertz99660e12014-02-19 15:04:42 +0100299 void StartProcessingRequest() LOCKS_EXCLUDED(process_request_lock_);
300 void EndProcessingRequest() LOCKS_EXCLUDED(process_request_lock_);
301 void WaitForProcessingRequest() LOCKS_EXCLUDED(process_request_lock_);
302
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700303 public: // TODO: fix privacy
Elliott Hughes376a7a02011-10-24 18:35:55 -0700304 const JdwpOptions* options_;
Elliott Hughes376a7a02011-10-24 18:35:55 -0700305
Elliott Hughesa21039c2012-06-21 12:09:25 -0700306 private:
Elliott Hughes376a7a02011-10-24 18:35:55 -0700307 /* wait for creation of the JDWP thread */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700308 Mutex thread_start_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
309 ConditionVariable thread_start_cond_ GUARDED_BY(thread_start_lock_);
Elliott Hughes376a7a02011-10-24 18:35:55 -0700310
Elliott Hughes475fc232011-10-25 15:00:35 -0700311 pthread_t pthread_;
312 Thread* thread_;
Elliott Hughesa21039c2012-06-21 12:09:25 -0700313
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700314 volatile int32_t debug_thread_started_ GUARDED_BY(thread_start_lock_);
Elliott Hughesa21039c2012-06-21 12:09:25 -0700315 ObjectId debug_thread_id_;
316
Elliott Hughes74847412012-06-20 18:10:21 -0700317 private:
Elliott Hughes376a7a02011-10-24 18:35:55 -0700318 bool run;
319
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700320 public: // TODO: fix privacy
Elliott Hughes68a5e3c2013-04-17 17:13:35 -0700321 JdwpNetStateBase* netState;
Elliott Hughes376a7a02011-10-24 18:35:55 -0700322
Elliott Hughesa21039c2012-06-21 12:09:25 -0700323 private:
324 // For wait-for-debugger.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700325 Mutex attach_lock_ ACQUIRED_AFTER(thread_start_lock_);
326 ConditionVariable attach_cond_ GUARDED_BY(attach_lock_);
Elliott Hughes376a7a02011-10-24 18:35:55 -0700327
Elliott Hughesa21039c2012-06-21 12:09:25 -0700328 // Time of last debugger activity, in milliseconds.
329 int64_t last_activity_time_ms_;
Elliott Hughes376a7a02011-10-24 18:35:55 -0700330
Elliott Hughesa21039c2012-06-21 12:09:25 -0700331 // Global counters and a mutex to protect them.
Mathieu Chartier4b95e8f2013-07-15 16:32:50 -0700332 AtomicInteger request_serial_;
333 AtomicInteger event_serial_;
Elliott Hughes376a7a02011-10-24 18:35:55 -0700334
Elliott Hughesa21039c2012-06-21 12:09:25 -0700335 // Linked list of events requested by the debugger (breakpoints, class prep, etc).
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100336 Mutex event_list_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Elliott Hughesa21039c2012-06-21 12:09:25 -0700337 JdwpEvent* event_list_ GUARDED_BY(event_list_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100338 size_t event_list_size_ GUARDED_BY(event_list_lock_); // Number of elements in event_list_.
339 size_t full_deoptimization_requests_ GUARDED_BY(event_list_lock_); // Number of events requiring
340 // full deoptimization.
Elliott Hughes376a7a02011-10-24 18:35:55 -0700341
Elliott Hughesa21039c2012-06-21 12:09:25 -0700342 // Used to synchronize suspension of the event thread (to avoid receiving "resume"
343 // events before the thread has finished suspending itself).
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700344 Mutex event_thread_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
345 ConditionVariable event_thread_cond_ GUARDED_BY(event_thread_lock_);
Elliott Hughesa21039c2012-06-21 12:09:25 -0700346 ObjectId event_thread_id_;
Elliott Hughes376a7a02011-10-24 18:35:55 -0700347
Sebastien Hertz99660e12014-02-19 15:04:42 +0100348 // Used to synchronize request processing and event sending (to avoid sending an event before
349 // sending the reply of a command being processed).
Sebastien Hertz400a3a92014-02-24 14:56:21 +0100350 Mutex process_request_lock_ ACQUIRED_AFTER(event_thread_lock_);
Sebastien Hertz99660e12014-02-19 15:04:42 +0100351 ConditionVariable process_request_cond_ GUARDED_BY(process_request_lock_);
352 bool processing_request_ GUARDED_BY(process_request_lock_);
353
Elliott Hughesa21039c2012-06-21 12:09:25 -0700354 bool ddm_is_active_;
Elliott Hughes64f574f2013-02-20 14:57:12 -0800355
356 bool should_exit_;
357 int exit_status_;
Elliott Hughes376a7a02011-10-24 18:35:55 -0700358};
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700359
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800360std::string DescribeField(const FieldId& field_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
361std::string DescribeMethod(const MethodId& method_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
362std::string DescribeRefTypeId(const RefTypeId& ref_type_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
363
364class Request {
365 public:
Elliott Hughescb693062013-02-21 09:48:08 -0800366 Request(const uint8_t* bytes, uint32_t available);
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800367 ~Request();
368
369 std::string ReadUtf8String();
370
371 // Helper function: read a variable-width value from the input buffer.
372 uint64_t ReadValue(size_t width);
373
374 int32_t ReadSigned32(const char* what);
375
376 uint32_t ReadUnsigned32(const char* what);
377
378 FieldId ReadFieldId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
379
380 MethodId ReadMethodId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
381
382 ObjectId ReadObjectId(const char* specific_kind);
383
384 ObjectId ReadArrayId();
385
386 ObjectId ReadObjectId();
387
388 ObjectId ReadThreadId();
389
390 ObjectId ReadThreadGroupId();
391
392 RefTypeId ReadRefTypeId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
393
394 FrameId ReadFrameId();
395
396 template <typename T> T ReadEnum1(const char* specific_kind) {
Elliott Hughescb693062013-02-21 09:48:08 -0800397 T value = static_cast<T>(Read1());
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800398 VLOG(jdwp) << " " << specific_kind << " " << value;
399 return value;
400 }
401
402 JdwpTag ReadTag();
403
404 JdwpTypeTag ReadTypeTag();
405
406 JdwpLocation ReadLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
407
408 JdwpModKind ReadModKind();
409
Elliott Hughescb693062013-02-21 09:48:08 -0800410 //
411 // Return values from this JDWP packet's header.
412 //
413 size_t GetLength() { return byte_count_; }
414 uint32_t GetId() { return id_; }
415 uint8_t GetCommandSet() { return command_set_; }
416 uint8_t GetCommand() { return command_; }
417
418 // Returns the number of bytes remaining.
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800419 size_t size() { return end_ - p_; }
Elliott Hughescb693062013-02-21 09:48:08 -0800420
421 // Returns a pointer to the next byte.
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800422 const uint8_t* data() { return p_; }
423
424 void Skip(size_t count) { p_ += count; }
425
426 void CheckConsumed();
427
428 private:
Elliott Hughescb693062013-02-21 09:48:08 -0800429 uint8_t Read1();
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800430 uint16_t Read2BE();
Elliott Hughescb693062013-02-21 09:48:08 -0800431 uint32_t Read4BE();
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800432 uint64_t Read8BE();
433
Elliott Hughescb693062013-02-21 09:48:08 -0800434 uint32_t byte_count_;
435 uint32_t id_;
436 uint8_t command_set_;
437 uint8_t command_;
438
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800439 const uint8_t* p_;
440 const uint8_t* end_;
441
442 DISALLOW_COPY_AND_ASSIGN(Request);
443};
444
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700445} // namespace JDWP
446
447} // namespace art
448
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700449#endif // ART_RUNTIME_JDWP_JDWP_H_