安装和使用 Intel PIn

2 篇文章 0 订阅

一、  安装

在官网http://www.pintool.org/下载压缩包然后解压就行了

Building the Example Tools for Linux

To build allexamples in a directory:

$ cd source/tools/ManualExamples
$ make all

To build and run a specific example (e.g., inscount0):

$ cd source/tools/ManualExamples
$ make inscount0.test

To build a specific example without running it (e.g., inscount0):

$ cd source/tools/ManualExamples
$ make obj-intel64/inscount0.so

The above applies to the Intel(R) 64 architecture. For the IA-32architecture, use "obj-ia32" instead of "obj-intel64":

$ cd source/tools/ManualExamples
$ make obj-ia32/inscount0.so

二、在windows上安装并运行一个例子

1.     之前的Pin版本中,支持通过MicrosoftVisual Studio 2010的命令行运行nmake之类的批处理命令,从Pin 2.12版本开始,需要基于cygwin make来进行编译

2.     Cygwin安装的时候,默认不安装make工具,所以在安装Cygwin时要选择安装make工具

3.     安装好Cygwin之后,将其安装目录下的bin目录,如“D:\cygwin\bin”加入到环境变量path中(最好加在其他所有变量之前,这样保证可以先用Cygwin进行解析),之后就可以直接在cmd中使用Cygwin的命令。例如:tar, ls, grep,make等

4.     下载的Pin是个压缩包,解压即可。将Pin解压后的文件夹的位置(pin.exe上面一层文件夹)加入到path中,即可在命令行中使用Pin命令。

5.     进入到source/tools/ManualExamples中,用make命令(同linux)可以编译所有例子。编译好后进入对应的32位或64位平台的文件夹中可以看到生成文件,windows下大多数生成的都是dll文件。然后使用pin命令pin -t itrace.dll --"test.exe"即可运行itrace这个例子对test.exe(是自己编的一个exe放到相同目录下了,如果在其他地方要用完整的路径)进行分析,这个例子是会输出所有的test.exe的指令的地址到文件itrace.out中。运行完后可以查看该文件。

该例子代码是source/tools/ManualExamples/itrace.cpp:

#include <stdio.h>
#include "pin.H"
FILE * trace;

// This function is called before every instruction is executed
// and prints the IP
VOID printip(VOID *ip) { fprintf(trace, "%p\n", ip); }

// Pin calls this function every time a new instruction is encountered
VOID Instruction(INS ins, VOID *v)
{
    // Insert a call to printip before every instruction, and pass it the IP
    INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)printip, IARG_INST_PTR, IARG_END);
}

// This function is called when the application exits
VOID Fini(INT32 code, VOID *v)
{
    fprintf(trace, "#eof\n");
    fclose(trace);
}

/*Print Help Message */

INT32 Usage()
{
    PIN_ERROR("This Pintool prints the IPs of every instruction executed\n" + KNOB_BASE::StringKnobSummary() + "\n");
    return -1;
}

int main(int argc, char * argv[])
{
    trace = fopen("itrace.out", "w");
    
    // Initialize pin
    if (PIN_Init(argc, argv)) return Usage();

    // Register Instruction to be called to instrument instructions
    INS_AddInstrumentFunction(Instruction, 0);

    // Register Fini to be called when the application exits
    PIN_AddFiniFunction(Fini, 0);
    
    // Start the program, never returns
    PIN_StartProgram();
    
    return 0;
}

生成的结果文件:


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值