Skip to content

Instantly share code, notes, and snippets.

@PollyP
Last active December 19, 2023 14:52
Show Gist options
  • Save PollyP/e50959ab97b15c83d4506dcf38753ef5 to your computer and use it in GitHub Desktop.
Save PollyP/e50959ab97b15c83d4506dcf38753ef5 to your computer and use it in GitHub Desktop.
Building and Running Intel Pintools with VS 2019 on Windows 10

Building Intel pintools with Visual Studio 2019 on Windows 10

Setting up the Intel pin build environment

I started with a Windows 10 Enterprise Evaluation VM, version 1809, from here: https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/ Then I installed the needed tools:

  • Install Visual Studio Community 2019 Edition from https://visualstudio.microsoft.com/downloads/, version 16.4.2. Make sure to install the Desktop development for C++ workload.

  • Install GNU's make, version 4.2.1, using Cygwin's 64-bit installer. Cygwin installer link here: https://cygwin.com/install.html.

  • If needed, create VS 32- and 64-bit developer command windows shortcuts.

    My 32-bit shortcut: %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat""

    My 64-bit shortcut: %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"".

  • Install the Windows version of Intel pin tools from https://software.intel.com/en-us/articles/pin-a-binary-instrumentation-tool-downloads. I used Intel pin version pin-3.11-97998-g7ecce2dac-msvc-windows.

Building and running an example pintool to use with a 32-bit process

  • Open a VS 2019 32-bit developer command window

  • Cd to the source\tools\SimpleExamples folder in the Intel pin folder

  • Add the Cygwin bin directory to your path: set PATH=%PATH%;\cygwin64\bin

  • Build the pintool DLL: make obj-ia32/icount.dll TARGET=ia32

  • Now run the pintool against your application. In this case, I have the 32-bit version of pslist.exe from the System Internals Suite in my home directory:

    ..\..\..\pin.exe -t obj-ia32\icount.dll -- c:\Users\IEUser\pslist.exe

The instruction count will print out at the end of the pslist.exe output.

Building and running an example pintool to use with a 64-bit process

  • Open a VS 2019 64-bit developer command window

  • Cd to the source\tools\SimpleExamples folder in the Intel pin folder

  • Add the Cygwin bin directory to your path: set PATH=%PATH%;\cygwin64\bin

  • Build the pintool DLL: make obj-intel64/icount.dll TARGET=intel64

  • Now run the pintool against your application. In this case, I have the 64-bit version of pslist.exe from the System Internals Suite in my home directory:

    ..\..\..\pin.exe -t obj-intel64\icount.dll -- c:\Users\IEUser\pslist64.exe

The instruction count will print out at the end of the pslist64.exe output.

@PollyP
Copy link
Author

PollyP commented Feb 19, 2020

Hint: if you're trying to compile a pintool that includes Windows.h (e.g. the w_malloctrace.cpp example) in VS and VS can't find it, make sure you have the preprocessor configured to define WINDOWS_H_PATH to point to Windows.h in your Windows SDK.

@bytehow
Copy link

bytehow commented Nov 26, 2020

This is awesome, thanks for this! Did you manage to get a pintool that requires Windows.h to compile correctly from within Visual Studio (using the provided MyPinTool vsproject)

@PollyP
Copy link
Author

PollyP commented Dec 1, 2020

Hi, you might take a look at my TraceVizTool repo, which imports Windows.h.

@sundarleo19
Copy link

@PollyP Thanks great share. I used pin version 3.20 facing issues "make: *** [../../../source/tools/Config/makefile.default.rules:217: obj-intel64/icount.obj] Error 2" make files are not created inside obj-intel64 folder. Can you please confirm whether the same works in pin version 3.20 ?

C:\pin-3.20-98437-gf02b61307-msvc-windows\source\tools\SimpleExamples>make obj-intel64/icount.dll TARGET=intel64
mkdir -p obj-intel64/
cl /EHs- /EHa- /wd4530 /DTARGET_WINDOWS /nologo /Gy /Oi- /GR- /GS- /DPIN_CRT=1 /D_WINDOWS_H_PATH_="C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um" /D__LP64__ /Zc:threadSafeInit- /Zc:sizedDealloc- /wd5208 /DTARGET_IA32E /DHOST_IA32E /I../../../source/include/pin /I../../../source/include/pin/gen -I../../../extras/stlport/include -I../../../extras -I../../../extras/libstdc++/include -I../../../extras/crt/include -I../../../extras/crt -I../../../extras/crt/include/arch-x86_64 -I../../../extras/crt/include/kernel/uapi -I../../../extras/crt/include/kernel/uapi/asm-x86 /FIinclude/msvc_compat.h /I../../../extras/components/include /I../../../extras/xed-intel64/include/xed /I../../../source/tools/Utils /I../../../source/tools/InstLib /MD /O2 /c /Foobj-intel64/icount.obj icount.cpp
icount.cpp
../../../extras/stlport/include\stl/char_traits.h(83): error C2118: negative subscript
make: *** [../../../source/tools/Config/makefile.default.rules:217: obj-intel64/icount.obj] Error 2

@brandonros
Copy link

C:\Users\Brandon\Desktop\pin-3.21-98484-ge7cd811fd-msvc-windows\pin-3.21-98484-ge7cd811fd-msvc-windows\source\tools\SimpleExamples>%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat""
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.11.14
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Users\Brandon\Desktop\pin-3.21-98484-ge7cd811fd-msvc-windows\pin-3.21-98484-ge7cd811fd-msvc-windows\source\tools\SimpleExamples>set PATH=%PATH%;C:\msys64\mingw64\bin

C:\Users\Brandon\Desktop\pin-3.21-98484-ge7cd811fd-msvc-windows\pin-3.21-98484-ge7cd811fd-msvc-windows\source\tools\SimpleExamples>make obj-intel64/icount.dll TARGET=intel64
mkdir -p obj-intel64/
The syntax of the command is incorrect.
../../../source/tools/Config/makefile.default.rules:50: recipe for target 'obj-intel64/' failed
make: *** [obj-intel64/] Error 1

C:\Users\Brandon\Desktop\pin-3.21-98484-ge7cd811fd-msvc-windows\pin-3.21-98484-ge7cd811fd-msvc-windows\source\tools\SimpleExamples>

mkdir issues?

@PollyP
Copy link
Author

PollyP commented Jun 11, 2022

Hi @brandonros, my gist was tested against 3.11 pintools, a release from several years ago. I'm not surprised that you're running into problems using it with 3.21 pintools. I haven't worked on pintools since 2020, so I don't have any updates for the more recent releases.

It might be worthwhile to check out the pinheads mailing list on groups.io. They are definitely the pintools experts.

@MrBeanc
Copy link

MrBeanc commented Jun 17, 2022

Hello, could you share your version's pin-tool with me? I can't find the version of 3.11 on the Internet. The problem of failed installation bothered me for a long time ,thank you very much. My email is [email protected]

@PollyP
Copy link
Author

PollyP commented Jun 17, 2022

Hi @MrBeanc, it appears that you can still grab the pin tools from Intel's server even though they have removed the links from the pintools download page.

Linux/Mac: https://software.intel.com/sites/landingpage/pintool/downloads/pin-3.11-97998-g7ecce2dac-gcc-linux.tar.gz
Windows: https://software.intel.com/sites/landingpage/pintool/downloads/pin-3.11-97998-g7ecce2dac-msvc-windows.zip

@MrBeanc
Copy link

MrBeanc commented Jun 18, 2022

So great !!! I installed successfully using your method. Before that, I spent a lot of time on the wrong version. Thank you very much :)

@PollyP
Copy link
Author

PollyP commented Jun 19, 2022

Good deal @MrBeanc, thanks for letting me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment