

Traces usually begin at the target of a taken branch and end with an unconditional branch, including calls and returns. Trace instrumentation lets the Pintool inspect and instrument an executable one trace at a time. We call this mode of operation trace instrumentation.
How to pin a document to start menu code#
Instrumentation occurs immediately before a code sequence is executed for the first time. This is because the instrumentation is executed once, but analysis code is called many times.Īs described above, Pin's instrumentation is "just in time" (JIT). When writing tools, it is more important to tune the analysis code than the instrumentation code. For executables compiled with shared libraries this implies that the execution of the dynamic loader and all shared libraries will be visible to the Pintool. Pin and the Pintool control a program starting with the very first instruction. It also shares file descriptors and other process information with the executable. Hence the Pintool has access to all of the executable's data. Since a Pintool works like a plugin, it must run in the same address space as Pin and the executable to be instrumented. These callbacks are generally used to gather data or tool initialization or clean up. The Pintool can also register notification callback routines for events such as thread creation or forking. Pin makes sure that the integer and floating point register state is saved and restored as necessary and allow arguments to be passed to the functions. The analysis function gathers data about the application. It inspects the code to be generated, investigates its static properties, and decides if and where to inject calls to analysis functions. This instrumentation callback routine represents the instrumentation component. The Pintool registers instrumentation callback routines with Pin that are called from Pin whenever new code needs to be generated. Pintools can be thought of as plugins that can modify the code generation process inside Pin. Both components live in a single executable, a Pintool. These two components are instrumentation and analysis code.

Pin intercepts the execution of the first instruction of the executable and generates ("compiles") new code for the straight line code sequence starting at this instruction. The input to this compiler is not bytecode, however, but a regular executable. The best way to think about Pin is as a "just in time" (JIT) compiler. Avoiding Deadlocks in Multi-threaded Applications.Instrumenting Multi-threaded Applications.Floating Point Support in Analysis Routines.It is easy to derive new tools using the examples as a template. Pin includes the source code for a large number of example instrumentation tools like basic block profilers, cache simulators, instruction trace generators, etc. Limited access to symbol and debug information is available as well. Pin automatically saves and restores the registers that are overwritten by the injected code so the application continues to work. Pin provides a rich API that abstracts away the underlying instruction set idiosyncracies and allows context information such as register contents to be passed to the injected code as parameters. This also makes it possible to attach Pin to an already running process. The code is added dynamically while the executable is running. Pin allows a tool to insert arbitrary code (written in C or C++) in arbitrary places in the executable. It supports the Linux*, macOS* and Windows* operating systems and executables for the IA-32, Intel(R) 64 and Intel(R) Many Integrated Core architectures. Pin is a tool for the instrumentation of programs.
