-
Go to the PIN download page.
-
Download the most recent version for Linux ("Sep 02, 2014", when I looked)
-
Unpack the file, rename it to "PIN", and move it into
/path/to/, for convenience:$ tar -xf pin-2.14-67254-gcc.4.4.7-linux.tar.gz$ mv pin-2.14-67254-gcc.4.4.7-linux /path/to/PIN
At this point, the executable, /path/to/PIN/pin, is ready to use. The
following instructions are just for testing your setup.
-
Enter the PIN Examples directory:
$ cd /path/to/PIN/source/tools/ManualExamples -
Compile all of the existing PIN tools with
make:$ make -
Try to run then PIN instruction-count trace on a simple binary like
ls:$ ../../../pin -t obj-ia32/inscount0.so -- /bin/ls -
If it tells you "
Attach to pid xxxxx failed", you may need to enable arbitrary pthread tracing (arguably a security concern), by doing:$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scopeThen try step #6 again -
If it tells you "
E:Unable to load obj-ia32/inscount0.so", then you may need to use the instruction-count tool compiled for a different architecture:$ ../../../pin -t obj-intel64/inscount0.so -- /bin/ls -
Once PIN traces the
lsexecution successfully, in addition to the expectedlsoutput to the console, the tool will create a file calledinscount.outcontaining a readout of the number of machine instructions performed:$ cat inscount.outCount 833535 -
If everything is working correctly, you may wish to make an alias for PIN:
$ alias pin='/path/to/PIN/pin'
-
Start at the PIN root directory:
$ cd /path/to/PIN/ -
Create a new directory for your tool, and move to it
$ mkdir source/tools/SOME_TOOL$ cd source/tools/SOME_TOOL -
Copy the source files for the existing
MyPinTool:$ cp -R ../MyPinTool/* . -
Rename the cpp file, and change
MyPinTooltoSOME_TOOLinmakefile.rules:$ mv MyPinTool.cpp SOME_TOOL.cpp$ sed -i 's/MyPinTool/SOME_TOOL/g' makefile.rules -
Now you are ready to start building your tool. You can edit the existing contents of
SOME_TOOL.cppand add your own stuff. The API reference is available here. I have also provided a stripped down version ofSOME_TOOL.cpphere. I believe this version may be easier to understand :-) -
Compile your tool by running
makein theSOME_TOOLdirectory:$ make -
You can now make an alias for your new tool:
$ alias SOME_TOOL='/path/to/PIN/pin -t /path/to/PIN/source/tools/SOME_TOOL/obj-ia32/SOME_TOOL.so -- ' -
Using the alias, you can now run your tool very easily:
$ SOME_TOOL /bin/ls