JdwpPriv.h revision 375fb116bcb817b37509ab579dbd55cdbb765cbf
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 * JDWP internal interfaces. 18 */ 19#ifndef DALVIK_JDWP_JDWPPRIV_H_ 20#define DALVIK_JDWP_JDWPPRIV_H_ 21 22#define LOG_TAG "jdwp" 23 24#include "jdwp/Jdwp.h" 25#include "jdwp/JdwpEvent.h" 26#include "Debugger.h" 27 28#include <pthread.h> 29#include <sys/uio.h> 30 31/* 32 * JDWP constants. 33 */ 34#define kJDWPHeaderLen 11 35#define kJDWPFlagReply 0x80 36 37/* DDM support */ 38#define kJDWPDdmCmdSet 199 /* 0xc7, or 'G'+128 */ 39#define kJDWPDdmCmd 1 40 41 42/* 43 * Transport-specific network status. 44 */ 45struct JdwpNetState; 46struct JdwpState; 47 48/* 49 * Transport functions. 50 */ 51struct 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); 64}; 65 66const JdwpTransport* dvmJdwpSocketTransport(); 67const JdwpTransport* dvmJdwpAndroidAdbTransport(); 68 69 70/* 71 * State for JDWP functions. 72 */ 73struct JdwpState { 74 JdwpStartupParams params; 75 76 /* wait for creation of the JDWP thread */ 77 pthread_mutex_t threadStartLock; 78 pthread_cond_t threadStartCond; 79 80 int debugThreadStarted; 81 pthread_t debugThreadHandle; 82 ObjectId debugThreadId; 83 bool run; 84 85 const JdwpTransport* transport; 86 JdwpNetState* netState; 87 88 /* for wait-for-debugger */ 89 pthread_mutex_t attachLock; 90 pthread_cond_t attachCond; 91 92 /* time of last debugger activity, in milliseconds */ 93 s8 lastActivityWhen; 94 95 /* global counters and a mutex to protect them */ 96 u4 requestSerial; 97 u4 eventSerial; 98 pthread_mutex_t serialLock; 99 100 /* 101 * Events requested by the debugger (breakpoints, class prep, etc). 102 */ 103 int numEvents; /* #of elements in eventList */ 104 JdwpEvent* eventList; /* linked list of events */ 105 pthread_mutex_t eventLock; /* guards numEvents/eventList */ 106 107 /* 108 * Synchronize suspension of event thread (to avoid receiving "resume" 109 * events before the thread has finished suspending itself). 110 */ 111 pthread_mutex_t eventThreadLock; 112 pthread_cond_t eventThreadCond; 113 ObjectId eventThreadId; 114 115 /* 116 * DDM support. 117 */ 118 bool ddmActive; 119}; 120 121 122/* reset all session-specific data */ 123void dvmJdwpResetState(JdwpState* state); 124 125/* atomic ops to get next serial number */ 126u4 dvmJdwpNextRequestSerial(JdwpState* state); 127u4 dvmJdwpNextEventSerial(JdwpState* state); 128 129/* get current time, in msec */ 130s8 dvmJdwpGetNowMsec(void); 131 132 133/* 134 * Transport functions. 135 */ 136INLINE bool dvmJdwpNetStartup(JdwpState* state, 137 const JdwpStartupParams* pParams) 138{ 139 return (*state->transport->startup)(state, pParams); 140} 141INLINE bool dvmJdwpAcceptConnection(JdwpState* state) { 142 return (*state->transport->accept)(state); 143} 144INLINE bool dvmJdwpEstablishConnection(JdwpState* state) { 145 return (*state->transport->establish)(state); 146} 147INLINE void dvmJdwpCloseConnection(JdwpState* state) { 148 (*state->transport->close)(state); 149} 150INLINE void dvmJdwpNetShutdown(JdwpState* state) { 151 (*state->transport->shutdown)(state); 152} 153INLINE void dvmJdwpNetFree(JdwpState* state) { 154 (*state->transport->free)(state); 155} 156INLINE bool dvmJdwpIsTransportDefined(JdwpState* state) { 157 return state != NULL && state->transport != NULL; 158} 159INLINE bool dvmJdwpIsConnected(JdwpState* state) { 160 return state != NULL && (*state->transport->isConnected)(state); 161} 162INLINE bool dvmJdwpAwaitingHandshake(JdwpState* state) { 163 return (*state->transport->awaitingHandshake)(state); 164} 165INLINE bool dvmJdwpProcessIncoming(JdwpState* state) { 166 return (*state->transport->processIncoming)(state); 167} 168INLINE bool dvmJdwpSendRequest(JdwpState* state, ExpandBuf* pReq) { 169 return (*state->transport->sendRequest)(state, pReq); 170} 171INLINE bool dvmJdwpSendBufferedRequest(JdwpState* state, 172 const struct iovec* iov, int iovcnt) 173{ 174 return (*state->transport->sendBufferedRequest)(state, iov, iovcnt); 175} 176 177#endif // DALVIK_JDWP_JDWPPRIV_H_ 178