1

I am trying to develop a Pintool on Windows. But so far I have been unable to configure or execute PIN. I have Microsoft Visual Studio 10.0 installed on my system. I have also downloaded and unzipped pin from its website.

On windows, "pin" command needs ".dll" file of pintool to execute. Suppose I want to execute "icount.cpp" on "prog1.exe". How can I do this?

How can I use Visual Studio to develop my own tools? I have gone through tutorials and I know what to writ, but I am not getting where and how to start?

Thanks you in advance.

2

The fastest and less cumbersome way I know is to make a copy of MyPinTool directory (under <pin dir>\source\tools\ and overwrite the file MyPinTool.cpp with your own code.

Open the MyPinTool.sln in Visual Studio and build your target. After that you can rename the DLL to whatever you want.

It is not an elegant solution but it gets the job done. In the end, you want to spent your time writing your PinTool and not annoyed with compiler specific settings...

1

I was able to find a blog which helped me configure Visual Studio 10 to develop my own tools. Here is the link to blog . The steps mentioned are generalized. But one thing I observed was that few directory names were different in my Pin installation. So please keep in mind to update those names. For some weird reasons I had to add "\LIBPATH:(path to additional library directories)" variable to Command Line Linker Options.

Also in the beginning of each cpp file mention

#define _SECURE_SCL 0

One common error you may face is "Error:LNK1104:Cannot open file* **". You can refer to this link to solve the issue.

EDIT: To execute the PIN tool:

Build the solution in Release configuration. I have extracted PIN inside my solution directory itself. Go to directory where pin.exe exists. Execute command in below format in command prompt:

pin -t [location (with file name) of solution DLL in release direcroty] -- [location (with file name) of application to execute]

Hope this will be helpful for anyone facing this issue in future.

0
1

Carlos's answer is more of a workaround, but it's so much spot on. Getting all the right knobs right is an insane job. And even more so with version 3 that switched away from whatever native runtime the OS may have, and started to use their own.

After half a day reversing the examples, I could come up with this (I'm assuming a 64 bit Windows target, but it shouldn't be difficult to notice what's architecture specific)

First of all you should get the include folders right (make sure to set PIN_ROOT in the first place though)

$(PIN_ROOT)\source\include\pin;$(PIN_ROOT)\source\include\pin\gen;$(PIN_ROOT)\source\tools\InstLib;$(PIN_ROOT)\extras\xed-intel64\include\xed;$(PIN_ROOT)\extras\components\include;$(PIN_ROOT)\extras\stlport\include;$(PIN_ROOT)\extras;$(PIN_ROOT)\extras\libstdc++\include;$(PIN_ROOT)\extras\crt\include;$(PIN_ROOT)\extras\crt;$(PIN_ROOT)\extras\crt\include\arch-x86;$(PIN_ROOT)\extras\crt\include\kernel\uapi;$(PIN_ROOT)\extras\crt\include\kernel\uapi\asm-x86;

Then, set these flags in the compiler: /MT /GR- /GS- /EHs- /EHa- /fp:strict /Oi- /FIinclude/msvc_compat.h

And these defines for the preprocessor: TARGET_IA32E;HOST_IA32E;TARGET_WINDOWS;WIN32;__PIN__=1;PIN_CRT=1;__LP64__ (please, really pay attention to the first two.. IA32E means x86-64 and their wrong combination can lead to countless ungodly issues with symbols and whatnot).

Remember that with the exception of like 3 headers ([xmm]intrin.h and somewhat limitedly windows.h) you cannot use any other one outside of pintool.

Next there is the linker. You need these folders

$(PIN_ROOT)\intel64\lib;$(PIN_ROOT)\intel64\lib-ext;$(PIN_ROOT)\extras\xed-intel64\lib;$(PIN_ROOT)\intel64\runtime\pincrt;

and these libraries, in the absolutest correct order (/NODEFAULTLIB is recommended)

pin.lib;xed.lib;pinvm.lib;kernel32.lib;pincrt.lib;ntdll-64.lib;crtbeginS.obj

(stlport-static.lib, m-static.lib, c-static.lib and os-apis.lib may also be needed in more complex situations)

Last but not least, you should add /export:main /SAFESEH:NO /IGNORE:4210 /IGNORE:4049 to the linker command line. For anything else give a check to the PinCRT whitepaper, whose reading I cannot recommend enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.