/* * Copyright 2002-2019 Intel Corporation. * * This software is provided to you as Sample Source Code as defined in the accompanying * End User License Agreement for the Intel(R) Software Development Products ("Agreement") * section 1.L. * * This software and the related documents are provided as is, with no express or implied * warranties, other than those that are expressly stated in the License. */ /*! @file * This file contains a test for correctness of the size of memory read for cmp instructions with repeat string operation prefix. (As well as a number of other tests for our handling of REPped string operations). */ #include #include #include #if defined(TARGET_LINUX) || defined(PIN_CRT) # include #endif #include "pin.H" using std::cout; using std::cerr; using std::endl; using std::string; using std::dec; using std::hex; #if defined(TARGET_WINDOWS) # define MAINNAME "main" #else # define MAINNAME "_start" #endif /* ===================================================================== */ /* Global Variables */ /* ===================================================================== */ THREADID mainThread = INVALID_THREADID; /* ===================================================================== */ /* Commandline Switches */ /* ===================================================================== */ LOCALVAR std::ofstream out; KNOB KnobOutputFile(KNOB_MODE_WRITEONCE, "pintool", "o", "repcmpsz_tool.out", "Output file"); /* ===================================================================== */ INT32 Usage() { cerr << "This tool prints out the size of memory reads done by two cmp \n" "instructions with repeat string operation prefix.\n" "\n"; cerr << KNOB_BASE::StringKnobSummary(); cerr << endl; return -1; } /* ===================================================================== */ VOID printSz(UINT32 sz, ADDRINT addr, UINT32 executing, ADDRINT count) { string ex = (executing ? " [TRUE]" : " [FALSE]"); out << "Read size : " << dec << sz << " %ecx " << dec << count << ex << endl; } VOID printCntVal(UINT32 val) { out << "After Count : " << dec << val << endl; } VOID printSzPredicated(UINT32 sz, ADDRINT addr, UINT32 executing, ADDRINT count) { out << "Predicated "; printSz(sz, addr, executing, count); } VOID printCntValPredicated(UINT32 val) { out << "Predicated "; printCntVal(val); } // Check that IF/THEN is working right, and that multiple AFTER instrumentation works as it should. LOCALVAR UINT32 icountBits[10]; LOCALVAR UINT32 icount[2]; UINT32 predicate(UINT32 bitNo, ADDRINT ip) { UINT32 ic = icount[0]; // out << hex << ip << " " << dec << ic << " Testing bit " << dec << bitNo << // " returns " << ((ic & (1<iCount; CONTEXT * savedCtx = &s->context; // Save the context if this was the first instruction if (seqNo == 0) PIN_SaveContext(ctx, savedCtx); else { for (UINT32 i=0; i