判断apk是否运行在调试状态的方法Debug. isDebuggerConnected之原理

Debug. isDebuggerConnected 可以判断当前apk是否运行在debug状态。
其实调用VMDebug. isDebuggerConnected方法


​/dalvik/​vm/​native/​dalvik_system_VMDebug.cpp
0337 static void Dalvik_dalvik_system_VMDebug_isDebuggerConnected(const u4* args,
0338     JValue* pResult)
0339 {
0340     UNUSED_PARAMETER(args);
0341 
0342     RETURN_BOOLEAN(dvmDbgIsDebuggerConnected());
0343 }


/dalvik/vm/Debugger.cpp
0443 bool dvmDbgIsDebuggerConnected()
0444 {
0445     return gDvm.debuggerActive;
0446 }


gDvm.debuggerActive是谁设置的呢?
/​dalvik/​vm/​Debugger.cpp
0393 void dvmDbgActive()
0394 {
0395     if (gDvm.debuggerActive)
0396         return;
0397 
0398     LOGI("Debugger is active");
0399     dvmInitBreakpoints();
0400     gDvm.debuggerActive = true;
0401     dvmEnableAllSubMode(kSubModeDebuggerActive);
0402 #if defined(WITH_JIT)
0403     dvmCompilerUpdateGlobalState();
0404 #endif
0405 }


dvmDbgActive又是谁调用的呢?
/​dalvik/​vm/​jdwp/​JdwpHandler.cpp
1876 void dvmJdwpProcessRequest(JdwpState* state, const JdwpReqHeader* pHeader,
1877     const u1* buf, int dataLen, ExpandBuf* pReply)
1878 {
1879     JdwpError result = ERR_NONE;
1880     int i, respLen;
1881 
1882     if (pHeader->cmdSet != kJDWPDdmCmdSet) {
1883         /*
1884          * Activity from a debugger, not merely ddms.  Mark us as having an
1885          * active debugger session, and zero out the last-activity timestamp
1886          * so waitForDebugger() doesn't return if we stall for a bit here.
1887          */
1888         dvmDbgActive();
1889         dvmQuasiAtomicSwap64(0, &state->lastActivityWhen);
1890     }


/​dalvik/​vm/​jdwp/​JdwpSocket.cpp
/​dalvik/​vm/​jdwp/​JdwpAdb.cpp
中各有一个 handlepacket调用了上述的dvmJdwpProcessRequest

你可能感兴趣的:(判断apk是否运行在调试状态的方法Debug. isDebuggerConnected之原理)