VOID doPause(VOID * arg) { for (int i = 0; i < TIMES; i++) { while (stopFlag == false) { PIN_Sleep(10); } stopFlag = false; printf("Threads to be stopped by internal thread %u\n", intTid); fflush(stdout); if (PIN_StopApplicationThreads(intTid)) { UINT32 nThreads = PIN_GetStoppedThreadCount(); printf("Threads stopped by internal thread %u : %u\n", intTid, nThreads); fflush(stdout); for (UINT32 index = 0; index < nThreads; index++) { THREADID tid = PIN_GetStoppedThreadId(index); const CONTEXT * ctxt = PIN_GetStoppedThreadContext(tid); printf(" Thread %u, IP = %llx, icount = %llu\n", tid, (long long unsigned int)PIN_GetContextReg(ctxt, REG_INST_PTR), icounter[tid]); } PIN_ResumeApplicationThreads(intTid); printf("Threads resumed by internal thread %u\n", intTid); fflush(stdout); } } return; }
VOID doPause(THREADID threadid) { assert(threadid < MAX_NUM_THREADS); ++icount[threadid]; if (icount[threadid] == stopPoint[threadid]) { printf("Threads to be stopped by application thread %u\n", threadid); fflush(stdout); // Pause threads in each LOOPS/2 instructions if (PIN_StopApplicationThreads(threadid)) { printf("Threads stopped by application thread %u\n", threadid); fflush(stdout); UINT32 nThreads = PIN_GetStoppedThreadCount(); for (UINT32 i = 0; i < nThreads; i++) { THREADID tid = PIN_GetStoppedThreadId(i); const CONTEXT * ctxt = PIN_GetStoppedThreadContext(tid); printf(" Thread %u, IP = %llx\n", tid, (long long unsigned int)PIN_GetContextReg(ctxt, REG_INST_PTR)); } PIN_ResumeApplicationThreads(threadid); printf("Threads resumed by application thread %u\n", threadid); fflush(stdout); // Reset stop point, do not try to stop in this thread any more. stopPoint[threadid] = 0; } else { // Probably collision with other thread calling PIN_StopApplicationThreads() // Update stop point. stopPoint[threadid] += PAUSE_INTERVAL; } } return; }