最近想采集某程序访存相关的trace,打算用PinTools。
Pin的使用很多博文已经进行了介绍,本文介绍关于VOID INS_InsertCall (INS ins, IPOINT action, AFUNPTR funptr,...)
的相关内容。
以</pin directory>/source/tools/ManualExamples/inscount0为例,该实例生成的.so可用来记录程序运行过程中指令的数量。
/*
* Copyright 2002-2020 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.
*/
#include <iostream>
#include <fstream>
#include "pin.H"
using std::cerr;
using std::ofstream;
using std::ios;
using std::string;
using std::endl;
ofstream OutFile;
// The running count of instructions is kept here
// make it static to help the compiler optimize docount
static UINT64 icount = 0;
// This function is called before every instruction is executed
VOID docount() {
icount++; }
// Pin calls this function every time a new instruction is encountered
VOID Instruction(INS ins, VOID *v)
{