blob: 6b15fa9d1b72316e92ffc046c589c59a55c2bfe9 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
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 McFadden01718122010-01-22 16:36:30 -080027
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080028#include <pthread.h>
Andy McFadden01718122010-01-22 16:36:30 -080029#include <sys/uio.h>
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080030
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;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080046struct JdwpState;
47
48/*
49 * Transport functions.
50 */
Carl Shapirod862faa2011-04-27 23:00:01 -070051struct JdwpTransport {
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080052 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 McFadden01718122010-01-22 16:36:30 -080062 bool (*sendBufferedRequest)(struct JdwpState* state,
63 const struct iovec* iov, int iovcnt);
Carl Shapirod862faa2011-04-27 23:00:01 -070064};
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080065
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
Andy McFaddenfc3d3162010-08-05 14:34:26 -070080 int debugThreadStarted;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080081 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 McFaddendeeeeb22010-06-16 08:32:04 -070092 /* time of last debugger activity, in milliseconds */
93 s8 lastActivityWhen;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080094
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 */
Andy McFaddendeeeeb22010-06-16 08:32:04 -0700130s8 dvmJdwpGetNowMsec(void);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800131
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}
Andy McFadden01718122010-01-22 16:36:30 -0800171INLINE bool dvmJdwpSendBufferedRequest(JdwpState* state,
172 const struct iovec* iov, int iovcnt)
Andy McFadden5442d462009-12-17 16:21:36 -0800173{
Andy McFadden01718122010-01-22 16:36:30 -0800174 return (*state->transport->sendBufferedRequest)(state, iov, iovcnt);
Andy McFadden5442d462009-12-17 16:21:36 -0800175}
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800176
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800177#endif /*_DALVIK_JDWP_JDWPPRIV*/