This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
mirrored from https://android.googlesource.com/platform/dalvik.git
-
Notifications
You must be signed in to change notification settings - Fork 263
/
Debugger.h
311 lines (269 loc) · 10 KB
/
Debugger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Dalvik-specific side of debugger support. (The JDWP code is intended to
* be relatively generic.)
*/
#ifndef _DALVIK_DEBUGGER
#define _DALVIK_DEBUGGER
#include "Common.h"
#include "Misc.h"
#include "jdwp/Jdwp.h"
#include <pthread.h>
/* fwd decl */
struct Object;
struct ClassObject;
struct Method;
struct Thread;
/*
* Used by StepControl to track a set of addresses associated with
* a single line.
*/
typedef struct AddressSet {
u4 setSize;
u1 set[1];
} AddressSet;
INLINE void dvmAddressSetSet(AddressSet *pSet, u4 toSet)
{
if (toSet < pSet->setSize) {
pSet->set[toSet/8] |= 1 << (toSet % 8);
}
}
INLINE bool dvmAddressSetGet(const AddressSet *pSet, u4 toGet)
{
if (toGet < pSet->setSize) {
return (pSet->set[toGet/8] & (1 << (toGet % 8))) != 0;
} else {
return false;
}
}
/*
* Single-step management.
*/
typedef struct StepControl {
/* request */
enum JdwpStepSize size;
enum JdwpStepDepth depth;
struct Thread* thread; /* don't deref; for comparison only */
/* current state */
bool active;
const struct Method* method;
int line; /* line #; could be -1 */
const AddressSet* pAddressSet; /* if non-null, address set for line */
int frameDepth;
} StepControl;
/*
* Invoke-during-breakpoint support.
*/
typedef struct DebugInvokeReq {
/* boolean; only set when we're in the tail end of an event handler */
bool ready;
/* boolean; set if the JDWP thread wants this thread to do work */
bool invokeNeeded;
/* request */
struct Object* obj; /* not used for ClassType.InvokeMethod */
struct Object* thread;
struct ClassObject* clazz;
struct Method* method;
u4 numArgs;
u8* argArray; /* will be NULL if numArgs==0 */
u4 options;
/* result */
JdwpError err;
u1 resultTag;
JValue resultValue;
ObjectId exceptObj;
/* condition variable to wait on while the method executes */
pthread_mutex_t lock;
pthread_cond_t cv;
} DebugInvokeReq;
/* system init/shutdown */
bool dvmDebuggerStartup(void);
void dvmDebuggerShutdown(void);
void dvmDbgInitMutex(pthread_mutex_t* pMutex);
void dvmDbgLockMutex(pthread_mutex_t* pMutex);
void dvmDbgUnlockMutex(pthread_mutex_t* pMutex);
void dvmDbgInitCond(pthread_cond_t* pCond);
void dvmDbgCondWait(pthread_cond_t* pCond, pthread_mutex_t* pMutex);
void dvmDbgCondSignal(pthread_cond_t* pCond);
void dvmDbgCondBroadcast(pthread_cond_t* pCond);
/*
* Return the DebugInvokeReq for the current thread.
*/
DebugInvokeReq* dvmDbgGetInvokeReq(void);
/*
* Enable/disable breakpoints and step modes. Used to provide a heads-up
* when the debugger attaches.
*/
void dvmDbgConnected(void);
void dvmDbgActive(void);
void dvmDbgDisconnected(void);
/*
* Returns "true" if a debugger is connected. Returns "false" if it's
* just DDM.
*/
bool dvmDbgIsDebuggerConnected(void);
/*
* Time, in milliseconds, since the last debugger activity. Does not
* include DDMS activity. Returns -1 if there has been no activity.
* Returns 0 if we're in the middle of handling a debugger request.
*/
s8 dvmDbgLastDebuggerActivity(void);
/*
* Block/allow GC depending on what we're doing. These return the old
* status, which can be fed to dvmDbgThreadGoing() to restore the previous
* mode.
*/
int dvmDbgThreadRunning(void);
int dvmDbgThreadWaiting(void);
int dvmDbgThreadContinuing(int status);
/*
* The debugger wants the VM to exit.
*/
void dvmDbgExit(int status);
/*
* Class, Object, Array
*/
const char* dvmDbgGetClassDescriptor(RefTypeId id);
ObjectId dvmDbgGetClassObject(RefTypeId id);
RefTypeId dvmDbgGetSuperclass(RefTypeId id);
ObjectId dvmDbgGetClassLoader(RefTypeId id);
u4 dvmDbgGetAccessFlags(RefTypeId id);
bool dvmDbgIsInterface(RefTypeId id);
void dvmDbgGetClassList(u4* pNumClasses, RefTypeId** pClassRefBuf);
void dvmDbgGetVisibleClassList(ObjectId classLoaderId, u4* pNumClasses,
RefTypeId** pClassRefBuf);
void dvmDbgGetClassInfo(RefTypeId classId, u1* pTypeTag, u4* pStatus,
char** pSignature);
bool dvmDbgFindLoadedClassBySignature(const char* classDescriptor,
RefTypeId* pRefTypeId);
void dvmDbgGetObjectType(ObjectId objectId, u1* pRefTypeTag,
RefTypeId* pRefTypeId);
u1 dvmDbgGetClassObjectType(RefTypeId refTypeId);
char* dvmDbgGetSignature(RefTypeId refTypeId);
const char* dvmDbgGetSourceFile(RefTypeId refTypeId);
char* dvmDbgGetObjectTypeName(ObjectId objectId);
int dvmDbgGetSignatureTag(const char* signature);
int dvmDbgGetObjectTag(ObjectId objectId, const char* type);
int dvmDbgGetTagWidth(int tag);
int dvmDbgGetArrayLength(ObjectId arrayId);
int dvmDbgGetArrayElementTag(ObjectId arrayId);
bool dvmDbgOutputArray(ObjectId arrayId, int firstIndex, int count,
ExpandBuf* pReply);
bool dvmDbgSetArrayElements(ObjectId arrayId, int firstIndex, int count,
const u1* buf);
ObjectId dvmDbgCreateString(const char* str);
ObjectId dvmDbgCreateObject(RefTypeId classId);
ObjectId dvmDbgCreateArrayObject(RefTypeId arrayTypeId, u4 length);
bool dvmDbgMatchType(RefTypeId instClassId, RefTypeId classId);
/*
* Method and Field
*/
const char* dvmDbgGetMethodName(RefTypeId refTypeId, MethodId id);
void dvmDbgOutputAllFields(RefTypeId refTypeId, bool withGeneric,
ExpandBuf* pReply);
void dvmDbgOutputAllMethods(RefTypeId refTypeId, bool withGeneric,
ExpandBuf* pReply);
void dvmDbgOutputAllInterfaces(RefTypeId refTypeId, ExpandBuf* pReply);
void dvmDbgOutputLineTable(RefTypeId refTypeId, MethodId methodId,
ExpandBuf* pReply);
void dvmDbgOutputVariableTable(RefTypeId refTypeId, MethodId id,
bool withGeneric, ExpandBuf* pReply);
int dvmDbgGetFieldTag(ObjectId objId, FieldId fieldId);
int dvmDbgGetStaticFieldTag(RefTypeId refTypeId, FieldId fieldId);
void dvmDbgGetFieldValue(ObjectId objId, FieldId fieldId, u1* ptr, int width);
void dvmDbgSetFieldValue(ObjectId objectId, FieldId fieldId, u8 value,
int width);
void dvmDbgGetStaticFieldValue(RefTypeId refTypeId, FieldId fieldId, u1* ptr,
int width);
void dvmDbgSetStaticFieldValue(RefTypeId refTypeId, FieldId fieldId,
u8 rawValue, int width);
char* dvmDbgStringToUtf8(ObjectId strId);
/*
* Thread, ThreadGroup, Frame
*/
char* dvmDbgGetThreadName(ObjectId threadId);
ObjectId dvmDbgGetThreadGroup(ObjectId threadId);
char* dvmDbgGetThreadGroupName(ObjectId threadGroupId);
ObjectId dvmDbgGetThreadGroupParent(ObjectId threadGroupId);
ObjectId dvmDbgGetSystemThreadGroupId(void);
ObjectId dvmDbgGetMainThreadGroupId(void);
bool dvmDbgGetThreadStatus(ObjectId threadId, u4* threadStatus,
u4* suspendStatus);
u4 dvmDbgGetThreadSuspendCount(ObjectId threadId);
bool dvmDbgThreadExists(ObjectId threadId);
bool dvmDbgIsSuspended(ObjectId threadId);
//void dvmDbgWaitForSuspend(ObjectId threadId);
void dvmDbgGetThreadGroupThreads(ObjectId threadGroupId,
ObjectId** ppThreadIds, u4* pThreadCount);
void dvmDbgGetAllThreads(ObjectId** ppThreadIds, u4* pThreadCount);
int dvmDbgGetThreadFrameCount(ObjectId threadId);
bool dvmDbgGetThreadFrame(ObjectId threadId, int num, FrameId* pFrameId,
JdwpLocation* pLoc);
ObjectId dvmDbgGetThreadSelfId(void);
void dvmDbgSuspendVM(bool isEvent);
void dvmDbgResumeVM(void);
void dvmDbgSuspendThread(ObjectId threadId);
void dvmDbgResumeThread(ObjectId threadId);
void dvmDbgSuspendSelf(void);
bool dvmDbgGetThisObject(ObjectId threadId, FrameId frameId, ObjectId* pThisId);
void dvmDbgGetLocalValue(ObjectId threadId, FrameId frameId, int slot,
u1 tag, u1* buf, int expectedLen);
void dvmDbgSetLocalValue(ObjectId threadId, FrameId frameId, int slot,
u1 tag, u8 value, int width);
/*
* Debugger notification
*/
void dvmDbgPostLocationEvent(const struct Method* method, int pcOffset,
struct Object* thisPtr, int eventFlags);
void dvmDbgPostException(void* throwFp, int throwRelPc, void* catchFp,
int catchRelPc, struct Object* exception);
void dvmDbgPostThreadStart(struct Thread* thread);
void dvmDbgPostThreadDeath(struct Thread* thread);
void dvmDbgPostClassPrepare(struct ClassObject* clazz);
// FieldAccess, FieldModification
/* for "eventFlags" */
enum {
DBG_BREAKPOINT = 0x01,
DBG_SINGLE_STEP = 0x02,
DBG_METHOD_ENTRY = 0x04,
DBG_METHOD_EXIT = 0x08,
};
bool dvmDbgWatchLocation(const JdwpLocation* pLoc);
void dvmDbgUnwatchLocation(const JdwpLocation* pLoc);
bool dvmDbgConfigureStep(ObjectId threadId, enum JdwpStepSize size,
enum JdwpStepDepth depth);
void dvmDbgUnconfigureStep(ObjectId threadId);
JdwpError dvmDbgInvokeMethod(ObjectId threadId, ObjectId objectId,
RefTypeId classId, MethodId methodId, u4 numArgs, u8* argArray,
u4 options, u1* pResultTag, u8* pResultValue, ObjectId* pExceptObj);
void dvmDbgExecuteMethod(DebugInvokeReq* pReq);
/* Make an AddressSet for a line, for single stepping */
const AddressSet *dvmAddressSetForLine(const struct Method* method, int line);
/* perform "late registration" of an object ID */
void dvmDbgRegisterObjectId(ObjectId id);
/*
* DDM support.
*/
bool dvmDbgDdmHandlePacket(const u1* buf, int dataLen, u1** pReplyBuf,
int* pReplyLen);
void dvmDbgDdmConnected(void);
void dvmDbgDdmDisconnected(void);
void dvmDbgDdmSendChunk(int type, size_t len, const u1* buf);
void dvmDbgDdmSendChunkV(int type, const struct iovec* iov, int iovcnt);
#define CHUNK_TYPE(_name) \
((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
#endif /*_DALVIK_DEBUGGER*/