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.
18 * Dalvik-specific side of debugger support. (The JDWP code is intended to
19 * be relatively generic.)
21 #ifndef _DALVIK_DEBUGGER
22 #define _DALVIK_DEBUGGER
26 #include "jdwp/Jdwp.h"
35 #define DEBUGGER_ACTIVE (gDvm.interpBreak & kSubModeDebuggerActive)
38 * Used by StepControl to track a set of addresses associated with
41 typedef struct AddressSet {
46 INLINE void dvmAddressSetSet(AddressSet *pSet, u4 toSet)
48 if (toSet < pSet->setSize) {
49 pSet->set[toSet/8] |= 1 << (toSet % 8);
53 INLINE bool dvmAddressSetGet(const AddressSet *pSet, u4 toGet)
55 if (toGet < pSet->setSize) {
56 return (pSet->set[toGet/8] & (1 << (toGet % 8))) != 0;
63 * Single-step management.
65 typedef struct StepControl {
67 enum JdwpStepSize size;
68 enum JdwpStepDepth depth;
69 struct Thread* thread; /* don't deref; for comparison only */
73 const struct Method* method;
74 int line; /* line #; could be -1 */
75 const AddressSet* pAddressSet; /* if non-null, address set for line */
80 * Invoke-during-breakpoint support.
82 typedef struct DebugInvokeReq {
83 /* boolean; only set when we're in the tail end of an event handler */
86 /* boolean; set if the JDWP thread wants this thread to do work */
90 struct Object* obj; /* not used for ClassType.InvokeMethod */
91 struct Object* thread;
92 struct ClassObject* clazz;
93 struct Method* method;
95 u8* argArray; /* will be NULL if numArgs==0 */
104 /* condition variable to wait on while the method executes */
105 pthread_mutex_t lock;
109 /* system init/shutdown */
110 bool dvmDebuggerStartup(void);
111 void dvmDebuggerShutdown(void);
113 void dvmDbgInitMutex(pthread_mutex_t* pMutex);
114 void dvmDbgLockMutex(pthread_mutex_t* pMutex);
115 void dvmDbgUnlockMutex(pthread_mutex_t* pMutex);
116 void dvmDbgInitCond(pthread_cond_t* pCond);
117 void dvmDbgCondWait(pthread_cond_t* pCond, pthread_mutex_t* pMutex);
118 void dvmDbgCondSignal(pthread_cond_t* pCond);
119 void dvmDbgCondBroadcast(pthread_cond_t* pCond);
122 * Return the DebugInvokeReq for the current thread.
124 DebugInvokeReq* dvmDbgGetInvokeReq(void);
127 * Enable/disable breakpoints and step modes. Used to provide a heads-up
128 * when the debugger attaches.
130 void dvmDbgConnected(void);
131 void dvmDbgActive(void);
132 void dvmDbgDisconnected(void);
135 * Returns "true" if a debugger is connected. Returns "false" if it's
138 bool dvmDbgIsDebuggerConnected(void);
141 * Time, in milliseconds, since the last debugger activity. Does not
142 * include DDMS activity. Returns -1 if there has been no activity.
143 * Returns 0 if we're in the middle of handling a debugger request.
145 s8 dvmDbgLastDebuggerActivity(void);
148 * Block/allow GC depending on what we're doing. These return the old
149 * status, which can be fed to dvmDbgThreadGoing() to restore the previous
152 int dvmDbgThreadRunning(void);
153 int dvmDbgThreadWaiting(void);
154 int dvmDbgThreadContinuing(int status);
157 * The debugger wants the VM to exit.
159 void dvmDbgExit(int status);
162 * Class, Object, Array
164 const char* dvmDbgGetClassDescriptor(RefTypeId id);
165 ObjectId dvmDbgGetClassObject(RefTypeId id);
166 RefTypeId dvmDbgGetSuperclass(RefTypeId id);
167 ObjectId dvmDbgGetClassLoader(RefTypeId id);
168 u4 dvmDbgGetAccessFlags(RefTypeId id);
169 bool dvmDbgIsInterface(RefTypeId id);
170 void dvmDbgGetClassList(u4* pNumClasses, RefTypeId** pClassRefBuf);
171 void dvmDbgGetVisibleClassList(ObjectId classLoaderId, u4* pNumClasses,
172 RefTypeId** pClassRefBuf);
173 void dvmDbgGetClassInfo(RefTypeId classId, u1* pTypeTag, u4* pStatus,
175 bool dvmDbgFindLoadedClassBySignature(const char* classDescriptor,
176 RefTypeId* pRefTypeId);
177 void dvmDbgGetObjectType(ObjectId objectId, u1* pRefTypeTag,
178 RefTypeId* pRefTypeId);
179 u1 dvmDbgGetClassObjectType(RefTypeId refTypeId);
180 char* dvmDbgGetSignature(RefTypeId refTypeId);
181 const char* dvmDbgGetSourceFile(RefTypeId refTypeId);
182 char* dvmDbgGetObjectTypeName(ObjectId objectId);
183 int dvmDbgGetSignatureTag(const char* signature);
184 int dvmDbgGetObjectTag(ObjectId objectId, const char* type);
185 int dvmDbgGetTagWidth(int tag);
187 int dvmDbgGetArrayLength(ObjectId arrayId);
188 int dvmDbgGetArrayElementTag(ObjectId arrayId);
189 bool dvmDbgOutputArray(ObjectId arrayId, int firstIndex, int count,
191 bool dvmDbgSetArrayElements(ObjectId arrayId, int firstIndex, int count,
194 ObjectId dvmDbgCreateString(const char* str);
195 ObjectId dvmDbgCreateObject(RefTypeId classId);
196 ObjectId dvmDbgCreateArrayObject(RefTypeId arrayTypeId, u4 length);
198 bool dvmDbgMatchType(RefTypeId instClassId, RefTypeId classId);
203 const char* dvmDbgGetMethodName(RefTypeId refTypeId, MethodId id);
204 void dvmDbgOutputAllFields(RefTypeId refTypeId, bool withGeneric,
206 void dvmDbgOutputAllMethods(RefTypeId refTypeId, bool withGeneric,
208 void dvmDbgOutputAllInterfaces(RefTypeId refTypeId, ExpandBuf* pReply);
209 void dvmDbgOutputLineTable(RefTypeId refTypeId, MethodId methodId,
211 void dvmDbgOutputVariableTable(RefTypeId refTypeId, MethodId id,
212 bool withGeneric, ExpandBuf* pReply);
214 int dvmDbgGetFieldTag(ObjectId objId, FieldId fieldId);
215 int dvmDbgGetStaticFieldTag(RefTypeId refTypeId, FieldId fieldId);
216 void dvmDbgGetFieldValue(ObjectId objId, FieldId fieldId, u1* ptr, int width);
217 void dvmDbgSetFieldValue(ObjectId objectId, FieldId fieldId, u8 value,
219 void dvmDbgGetStaticFieldValue(RefTypeId refTypeId, FieldId fieldId, u1* ptr,
221 void dvmDbgSetStaticFieldValue(RefTypeId refTypeId, FieldId fieldId,
222 u8 rawValue, int width);
224 char* dvmDbgStringToUtf8(ObjectId strId);
227 * Thread, ThreadGroup, Frame
229 char* dvmDbgGetThreadName(ObjectId threadId);
230 ObjectId dvmDbgGetThreadGroup(ObjectId threadId);
231 char* dvmDbgGetThreadGroupName(ObjectId threadGroupId);
232 ObjectId dvmDbgGetThreadGroupParent(ObjectId threadGroupId);
233 ObjectId dvmDbgGetSystemThreadGroupId(void);
234 ObjectId dvmDbgGetMainThreadGroupId(void);
236 bool dvmDbgGetThreadStatus(ObjectId threadId, u4* threadStatus,
238 u4 dvmDbgGetThreadSuspendCount(ObjectId threadId);
239 bool dvmDbgThreadExists(ObjectId threadId);
240 bool dvmDbgIsSuspended(ObjectId threadId);
241 //void dvmDbgWaitForSuspend(ObjectId threadId);
242 void dvmDbgGetThreadGroupThreads(ObjectId threadGroupId,
243 ObjectId** ppThreadIds, u4* pThreadCount);
244 void dvmDbgGetAllThreads(ObjectId** ppThreadIds, u4* pThreadCount);
245 int dvmDbgGetThreadFrameCount(ObjectId threadId);
246 bool dvmDbgGetThreadFrame(ObjectId threadId, int num, FrameId* pFrameId,
249 ObjectId dvmDbgGetThreadSelfId(void);
250 void dvmDbgSuspendVM(bool isEvent);
251 void dvmDbgResumeVM(void);
252 void dvmDbgSuspendThread(ObjectId threadId);
253 void dvmDbgResumeThread(ObjectId threadId);
254 void dvmDbgSuspendSelf(void);
256 bool dvmDbgGetThisObject(ObjectId threadId, FrameId frameId, ObjectId* pThisId);
257 void dvmDbgGetLocalValue(ObjectId threadId, FrameId frameId, int slot,
258 u1 tag, u1* buf, int expectedLen);
259 void dvmDbgSetLocalValue(ObjectId threadId, FrameId frameId, int slot,
260 u1 tag, u8 value, int width);
264 * Debugger notification
266 void dvmDbgPostLocationEvent(const struct Method* method, int pcOffset,
267 struct Object* thisPtr, int eventFlags);
268 void dvmDbgPostException(void* throwFp, int throwRelPc, void* catchFp,
269 int catchRelPc, struct Object* exception);
270 void dvmDbgPostThreadStart(struct Thread* thread);
271 void dvmDbgPostThreadDeath(struct Thread* thread);
272 void dvmDbgPostClassPrepare(struct ClassObject* clazz);
273 // FieldAccess, FieldModification
275 /* for "eventFlags" */
277 DBG_BREAKPOINT = 0x01,
278 DBG_SINGLE_STEP = 0x02,
279 DBG_METHOD_ENTRY = 0x04,
280 DBG_METHOD_EXIT = 0x08,
283 bool dvmDbgWatchLocation(const JdwpLocation* pLoc);
284 void dvmDbgUnwatchLocation(const JdwpLocation* pLoc);
285 bool dvmDbgConfigureStep(ObjectId threadId, enum JdwpStepSize size,
286 enum JdwpStepDepth depth);
287 void dvmDbgUnconfigureStep(ObjectId threadId);
289 JdwpError dvmDbgInvokeMethod(ObjectId threadId, ObjectId objectId,
290 RefTypeId classId, MethodId methodId, u4 numArgs, u8* argArray,
291 u4 options, u1* pResultTag, u8* pResultValue, ObjectId* pExceptObj);
292 void dvmDbgExecuteMethod(DebugInvokeReq* pReq);
294 /* Make an AddressSet for a line, for single stepping */
295 const AddressSet *dvmAddressSetForLine(const struct Method* method, int line);
297 /* perform "late registration" of an object ID */
298 void dvmDbgRegisterObjectId(ObjectId id);
303 bool dvmDbgDdmHandlePacket(const u1* buf, int dataLen, u1** pReplyBuf,
305 void dvmDbgDdmConnected(void);
306 void dvmDbgDdmDisconnected(void);
307 void dvmDbgDdmSendChunk(int type, size_t len, const u1* buf);
308 void dvmDbgDdmSendChunkV(int type, const struct iovec* iov, int iovcnt);
310 #define CHUNK_TYPE(_name) \
311 ((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
313 #endif /*_DALVIK_DEBUGGER*/