The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [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 | * 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" |
Andy McFadden | 0171812 | 2010-01-22 16:36:30 -0800 | [diff] [blame] | 27 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 28 | #include <pthread.h> |
Andy McFadden | 0171812 | 2010-01-22 16:36:30 -0800 | [diff] [blame] | 29 | #include <sys/uio.h> |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 | */ |
| 45 | struct JdwpNetState; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 46 | struct JdwpState; |
| 47 | |
| 48 | /* |
| 49 | * Transport functions. |
| 50 | */ |
Carl Shapiro | d862faa | 2011-04-27 23:00:01 -0700 | [diff] [blame^] | 51 | struct JdwpTransport { |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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); |
Andy McFadden | 0171812 | 2010-01-22 16:36:30 -0800 | [diff] [blame] | 62 | bool (*sendBufferedRequest)(struct JdwpState* state, |
| 63 | const struct iovec* iov, int iovcnt); |
Carl Shapiro | d862faa | 2011-04-27 23:00:01 -0700 | [diff] [blame^] | 64 | }; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 65 | |
| 66 | const JdwpTransport* dvmJdwpSocketTransport(); |
| 67 | const JdwpTransport* dvmJdwpAndroidAdbTransport(); |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | * State for JDWP functions. |
| 72 | */ |
| 73 | struct JdwpState { |
| 74 | JdwpStartupParams params; |
| 75 | |
| 76 | /* wait for creation of the JDWP thread */ |
| 77 | pthread_mutex_t threadStartLock; |
| 78 | pthread_cond_t threadStartCond; |
| 79 | |
Andy McFadden | fc3d316 | 2010-08-05 14:34:26 -0700 | [diff] [blame] | 80 | int debugThreadStarted; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 | |
Andy McFadden | deeeeb2 | 2010-06-16 08:32:04 -0700 | [diff] [blame] | 92 | /* time of last debugger activity, in milliseconds */ |
| 93 | s8 lastActivityWhen; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 */ |
| 123 | void dvmJdwpResetState(JdwpState* state); |
| 124 | |
| 125 | /* atomic ops to get next serial number */ |
| 126 | u4 dvmJdwpNextRequestSerial(JdwpState* state); |
| 127 | u4 dvmJdwpNextEventSerial(JdwpState* state); |
| 128 | |
| 129 | /* get current time, in msec */ |
Andy McFadden | deeeeb2 | 2010-06-16 08:32:04 -0700 | [diff] [blame] | 130 | s8 dvmJdwpGetNowMsec(void); |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 131 | |
| 132 | |
| 133 | /* |
| 134 | * Transport functions. |
| 135 | */ |
| 136 | INLINE bool dvmJdwpNetStartup(JdwpState* state, |
| 137 | const JdwpStartupParams* pParams) |
| 138 | { |
| 139 | return (*state->transport->startup)(state, pParams); |
| 140 | } |
| 141 | INLINE bool dvmJdwpAcceptConnection(JdwpState* state) { |
| 142 | return (*state->transport->accept)(state); |
| 143 | } |
| 144 | INLINE bool dvmJdwpEstablishConnection(JdwpState* state) { |
| 145 | return (*state->transport->establish)(state); |
| 146 | } |
| 147 | INLINE void dvmJdwpCloseConnection(JdwpState* state) { |
| 148 | (*state->transport->close)(state); |
| 149 | } |
| 150 | INLINE void dvmJdwpNetShutdown(JdwpState* state) { |
| 151 | (*state->transport->shutdown)(state); |
| 152 | } |
| 153 | INLINE void dvmJdwpNetFree(JdwpState* state) { |
| 154 | (*state->transport->free)(state); |
| 155 | } |
| 156 | INLINE bool dvmJdwpIsTransportDefined(JdwpState* state) { |
| 157 | return state != NULL && state->transport != NULL; |
| 158 | } |
| 159 | INLINE bool dvmJdwpIsConnected(JdwpState* state) { |
| 160 | return state != NULL && (*state->transport->isConnected)(state); |
| 161 | } |
| 162 | INLINE bool dvmJdwpAwaitingHandshake(JdwpState* state) { |
| 163 | return (*state->transport->awaitingHandshake)(state); |
| 164 | } |
| 165 | INLINE bool dvmJdwpProcessIncoming(JdwpState* state) { |
| 166 | return (*state->transport->processIncoming)(state); |
| 167 | } |
| 168 | INLINE bool dvmJdwpSendRequest(JdwpState* state, ExpandBuf* pReq) { |
| 169 | return (*state->transport->sendRequest)(state, pReq); |
| 170 | } |
Andy McFadden | 0171812 | 2010-01-22 16:36:30 -0800 | [diff] [blame] | 171 | INLINE bool dvmJdwpSendBufferedRequest(JdwpState* state, |
| 172 | const struct iovec* iov, int iovcnt) |
Andy McFadden | 5442d46 | 2009-12-17 16:21:36 -0800 | [diff] [blame] | 173 | { |
Andy McFadden | 0171812 | 2010-01-22 16:36:30 -0800 | [diff] [blame] | 174 | return (*state->transport->sendBufferedRequest)(state, iov, iovcnt); |
Andy McFadden | 5442d46 | 2009-12-17 16:21:36 -0800 | [diff] [blame] | 175 | } |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 176 | |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 177 | #endif /*_DALVIK_JDWP_JDWPPRIV*/ |