JdwpPriv.h revision 5442d46fe1d0645d786a289c1143e830a6699b14
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 20#define _DALVIK_JDWP_JDWPPRIV 21 22#define LOG_TAG "jdwp" 23 24#include "jdwp/Jdwp.h" 25#include "jdwp/JdwpEvent.h" 26#include "Debugger.h" 27#include <pthread.h> 28 29/* 30 * JDWP constants. 31 */ 32#define kJDWPHeaderLen 11 33#define kJDWPFlagReply 0x80 34 35/* DDM support */ 36#define kJDWPDdmCmdSet 199 /* 0xc7, or 'G'+128 */ 37#define kJDWPDdmCmd 1 38 39 40/* 41 * Transport-specific network status. 42 */ 43struct JdwpNetState; 44typedef struct JdwpNetState JdwpNetState; 45 46struct JdwpState; 47 48/* 49 * Transport functions. 50 */ 51typedef 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, const void* header, 63 size_t headerLen, const void* body, size_t bodyLen); 64} JdwpTransport; 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 bool 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; "sec" zeroed while processing */ 93 volatile long lastActivitySec; 94 volatile long lastActivityMsec; 95 96 /* global counters and a mutex to protect them */ 97 u4 requestSerial; 98 u4 eventSerial; 99 pthread_mutex_t serialLock; 100 101 /* 102 * Events requested by the debugger (breakpoints, class prep, etc). 103 */ 104 int numEvents; /* #of elements in eventList */ 105 JdwpEvent* eventList; /* linked list of events */ 106 pthread_mutex_t eventLock; /* guards numEvents/eventList */ 107 108 /* 109 * Synchronize suspension of event thread (to avoid receiving "resume" 110 * events before the thread has finished suspending itself). 111 */ 112 pthread_mutex_t eventThreadLock; 113 pthread_cond_t eventThreadCond; 114 ObjectId eventThreadId; 115 116 /* 117 * DDM support. 118 */ 119 bool ddmActive; 120}; 121 122 123/* reset all session-specific data */ 124void dvmJdwpResetState(JdwpState* state); 125 126/* atomic ops to get next serial number */ 127u4 dvmJdwpNextRequestSerial(JdwpState* state); 128u4 dvmJdwpNextEventSerial(JdwpState* state); 129 130/* get current time, in msec */ 131void dvmJdwpGetNowMsec(long* pSec, long* pMsec); 132 133 134/* 135 * Transport functions. 136 */ 137INLINE bool dvmJdwpNetStartup(JdwpState* state, 138 const JdwpStartupParams* pParams) 139{ 140 return (*state->transport->startup)(state, pParams); 141} 142INLINE bool dvmJdwpAcceptConnection(JdwpState* state) { 143 return (*state->transport->accept)(state); 144} 145INLINE bool dvmJdwpEstablishConnection(JdwpState* state) { 146 return (*state->transport->establish)(state); 147} 148INLINE void dvmJdwpCloseConnection(JdwpState* state) { 149 (*state->transport->close)(state); 150} 151INLINE void dvmJdwpNetShutdown(JdwpState* state) { 152 (*state->transport->shutdown)(state); 153} 154INLINE void dvmJdwpNetFree(JdwpState* state) { 155 (*state->transport->free)(state); 156} 157INLINE bool dvmJdwpIsTransportDefined(JdwpState* state) { 158 return state != NULL && state->transport != NULL; 159} 160INLINE bool dvmJdwpIsConnected(JdwpState* state) { 161 return state != NULL && (*state->transport->isConnected)(state); 162} 163INLINE bool dvmJdwpAwaitingHandshake(JdwpState* state) { 164 return (*state->transport->awaitingHandshake)(state); 165} 166INLINE bool dvmJdwpProcessIncoming(JdwpState* state) { 167 return (*state->transport->processIncoming)(state); 168} 169INLINE bool dvmJdwpSendRequest(JdwpState* state, ExpandBuf* pReq) { 170 return (*state->transport->sendRequest)(state, pReq); 171} 172INLINE bool dvmJdwpSendBufferedRequest(JdwpState* state, const void* header, 173 size_t headerLen, const void* body, size_t bodyLen) 174{ 175 return (*state->transport->sendBufferedRequest)(state, header, headerLen, 176 body, bodyLen); 177} 178 179#endif /*_DALVIK_JDWP_JDWPPRIV*/ 180