2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * JDWP internal interfaces.
19 #ifndef DALVIK_JDWP_JDWPPRIV_H_
20 #define DALVIK_JDWP_JDWPPRIV_H_
22 #define LOG_TAG "jdwp"
24 #include "jdwp/Jdwp.h"
25 #include "jdwp/JdwpEvent.h"
34 #define kJDWPHeaderLen 11
35 #define kJDWPFlagReply 0x80
38 #define kJDWPDdmCmdSet 199 /* 0xc7, or 'G'+128 */
43 * Transport-specific network status.
49 * Transport functions.
51 struct JdwpTransport {
52 bool (*startup)(struct JdwpState* state, const JdwpStartupParams* pParams);
53 bool (*accept)(struct JdwpState* state);
54 bool (*establish)(struct JdwpState* state);
55 void (*close)(struct JdwpState* state);
56 void (*shutdown)(struct JdwpState* state);
57 void (*free)(struct JdwpState* state);
58 bool (*isConnected)(struct JdwpState* state);
59 bool (*awaitingHandshake)(struct JdwpState* state);
60 bool (*processIncoming)(struct JdwpState* state);
61 bool (*sendRequest)(struct JdwpState* state, ExpandBuf* pReq);
62 bool (*sendBufferedRequest)(struct JdwpState* state,
63 const struct iovec* iov, int iovcnt);
66 const JdwpTransport* dvmJdwpSocketTransport();
67 const JdwpTransport* dvmJdwpAndroidAdbTransport();
71 * State for JDWP functions.
74 JdwpStartupParams params;
76 /* wait for creation of the JDWP thread */
77 pthread_mutex_t threadStartLock;
78 pthread_cond_t threadStartCond;
80 int debugThreadStarted;
81 pthread_t debugThreadHandle;
82 ObjectId debugThreadId;
85 const JdwpTransport* transport;
86 JdwpNetState* netState;
88 /* for wait-for-debugger */
89 pthread_mutex_t attachLock;
90 pthread_cond_t attachCond;
92 /* time of last debugger activity, in milliseconds */
95 /* global counters and a mutex to protect them */
98 pthread_mutex_t serialLock;
101 * Events requested by the debugger (breakpoints, class prep, etc).
103 int numEvents; /* #of elements in eventList */
104 JdwpEvent* eventList; /* linked list of events */
105 pthread_mutex_t eventLock; /* guards numEvents/eventList */
108 * Synchronize suspension of event thread (to avoid receiving "resume"
109 * events before the thread has finished suspending itself).
111 pthread_mutex_t eventThreadLock;
112 pthread_cond_t eventThreadCond;
113 ObjectId eventThreadId;
122 * Base class for JdwpNetState
124 class JdwpNetStateBase {
126 int clientSock; /* active connection to debugger */
129 ssize_t writePacket(ExpandBuf* pReply);
130 ssize_t writeBufferedPacket(const struct iovec* iov, int iovcnt);
133 pthread_mutex_t socketLock; /* socket synchronization */
137 /* reset all session-specific data */
138 void dvmJdwpResetState(JdwpState* state);
140 /* atomic ops to get next serial number */
141 u4 dvmJdwpNextRequestSerial(JdwpState* state);
142 u4 dvmJdwpNextEventSerial(JdwpState* state);
144 /* get current time, in msec */
145 s8 dvmJdwpGetNowMsec(void);
149 * Transport functions.
151 INLINE bool dvmJdwpNetStartup(JdwpState* state,
152 const JdwpStartupParams* pParams)
154 return (*state->transport->startup)(state, pParams);
156 INLINE bool dvmJdwpAcceptConnection(JdwpState* state) {
157 return (*state->transport->accept)(state);
159 INLINE bool dvmJdwpEstablishConnection(JdwpState* state) {
160 return (*state->transport->establish)(state);
162 INLINE void dvmJdwpCloseConnection(JdwpState* state) {
163 (*state->transport->close)(state);
165 INLINE void dvmJdwpNetShutdown(JdwpState* state) {
166 (*state->transport->shutdown)(state);
168 INLINE void dvmJdwpNetFree(JdwpState* state) {
169 (*state->transport->free)(state);
171 INLINE bool dvmJdwpIsTransportDefined(JdwpState* state) {
172 return state != NULL && state->transport != NULL;
174 INLINE bool dvmJdwpIsConnected(JdwpState* state) {
175 return state != NULL && (*state->transport->isConnected)(state);
177 INLINE bool dvmJdwpAwaitingHandshake(JdwpState* state) {
178 return (*state->transport->awaitingHandshake)(state);
180 INLINE bool dvmJdwpProcessIncoming(JdwpState* state) {
181 return (*state->transport->processIncoming)(state);
183 INLINE bool dvmJdwpSendRequest(JdwpState* state, ExpandBuf* pReq) {
184 return (*state->transport->sendRequest)(state, pReq);
186 INLINE bool dvmJdwpSendBufferedRequest(JdwpState* state,
187 const struct iovec* iov, int iovcnt)
189 return (*state->transport->sendBufferedRequest)(state, iov, iovcnt);
192 #endif // DALVIK_JDWP_JDWPPRIV_H_