And this is what PinTool does with ease. Sometimes camera focal length should be known. For example for tracking. But sometimes you have to deal with footage which is shot with unknown lens.
There are a lot of render settings simplifying work with PinTool. There is a Motion Blur mode for fast moving objects, automatically adjusted wireframe opacity helping to stay focused on tracking on different zoom levels and lit wireframe to underline model details even in wireframe mode. Colour setup knobs are also available for almost everything from wireframe to surface mask colour. All our nodes including FaceBuilder are available in Nuke Indie. You need to install the Learn More.
Menu Search Compare. Search: Search. You have no items to compare. False sharing can usually be avoided by padding critical data structures to the size of a cache line, or by rearranging the data layout of structures. Since Pin, the tool, and the application may each acquire and release locks, Pintool developers must take care to avoid deadlocks with either the application or Pin. Deadlocks generally occur when two threads acquire the same locks in a different order. For example, thread A acquires lock L1 and then acquires lock L2, while thread B acquires lock L2 and then acquires lock L1.
This will lead to a deadlock if thread A holds lock L1 and waits for L2 while thread B holds lock L2 and waits for L1.
To avoid such deadlocks, Pin imposes a hierarchy on the order in which locks must be acquired. Pin generally acquires its own internal locks before the tool acquires any lock e. Additionally, we assume that the application may acquire locks at the top of this hierarchy i. The following diagram illustrates the hierarchy:. Pintool developers should design their Pintools such that they never break this lock hierarchy, and they can do so by following these basic guidelines:.
While these guidelines are sufficient in most cases, they may turn out to be too restrictive for certain use-cases.
The next set of guidelines explains the conditions in which it is safe to relax the basic guidelines above:. To illustrate how to write Pintools, we present some simple examples.
In the web based version of the manual, you can click on a function in the Pin API to see its documentation. The above applies to the Intel R 64 architecture.
Open the Visual Studio Command Prompt corresponding to your target architecture, i. The example below instruments a program to count the total number of instructions executed. It inserts a call to docount before every instruction. When the program exits, it saves the count in the file inscount. Here is how to run it and display its output note that the file list is the ls output, so it may be different on your machine, similarly the instruction count will depend on the implementation of ls :.
The KNOB exhibited in the example below overwrites the default name for the output file. Tool command line options should be inserted between the tool name and the double dash "--".
In the previous example, we did not pass any arguments to docount , the analysis procedure. In this example, we show how to pass arguments. When calling an analysis procedure, Pin allows you to pass the instruction pointer, current value of registers, effective address of memory operations, constants, etc. With a small change, we can turn the instruction counting example into a Pintool that prints the address of every instruction that is executed.
This tool is useful for understanding the control flow of a program for debugging, or in processor design when simulating an instruction cache. We replace docount with printip , which prints the instruction address. It writes its output to the file itrace. The previous example instruments all instructions. Sometimes a tool may only want to instrument a class of instructions, like memory operations or branch instructions.
A tool can do this by using the Pin API which includes functions that classify and examine instructions. The basic API is common to all instruction sets and is described here. In this example, we show how to do more selective instrumentation by examining the instructions. This tool generates a trace of all memory addresses referenced by a program. This is also useful for debugging and for simulating a data cache in a processor. We only instrument instructions that read or write memory.
Since the instrumentation functions are only called once and the analysis functions are called every time an instruction is executed, it is much faster to instrument only the memory operations, as compared to the previous instruction trace example that instruments every instruction. The example below prints a message to a trace file every time and image is loaded or unloaded.
It really abuses the image instrumentation mode as the Pintool neither inspects the image nor adds instrumentation code. The example Simple Instruction Count Instruction Instrumentation computed the number of executed instructions by inserting a call before every instruction. In this example, we make it more efficient by counting the number of instructions in a BBL: Single entrance, single exit sequence of instructions at instrumentation time, and incrementing the counter once per BBL: Single entrance, single exit sequence of instructions , instead of once per instruction.
The example below instruments a program to count the number of times a procedure is called, and the total number of instructions executed in each procedure. When it finishes, it prints a profile to proccount. This function guarantees safe return to the caller even if the source or destination regions are inaccessible entirely or partially.
Use of this function also guarantees that the tool reads or writes the values used by the application. If the tool accessed these fields directly, it would see the modified values rather than the original ones. Pin provides tools with multiple ways to control the exection order of analysis calls.
The example below illustrates this behavior by instrumenting all return instructions in three different ways. Often one needs the know the value of the argument passed into a function, or the return value. You can use Pin to find this information. The example below prints the input argument for malloc and free , and the return value from malloc. Finding functions by name on Windows requires a different methodology.
Several symbols could resolve to the same function address. It is important to check all symbol names. The following example finds the function name in the symbol table, and uses the symbol address to find the appropriate RTN. The following example demonstrates using the ThreadStart and ThreadFini notification callbacks. Although ThreadStart and ThreadFini are executed under the VM and client locks, they could still contend with resources that are shared by other analysis routines.
Note that there is known isolation issue when using Pin on Windows. On Windows, a deadlock can occur if a tool opens a file in a callback when run on a multi-threaded application. To work around this problem, open one file in main, and tag the data with the thread ID. This problem does not exist on Linux. These APIs allow a tool to create thread-specific data. The example below demonstrates how to use these APIs.
Pin provides support for buffering data for processing. If all that your analysis callback does is to store its arguments into a buffer, then you should be able to use the buffering API instead, with some performance benefit. The buffer is allocated by each thread when it starts up, and deallocated when the thread exits. Pin does not serialize the calls to this callback, so it is the tool writers responsibilty to make sure this function is thread safe.
This example records the PC of all instructions that access memory, and the effective address accessed by the instruction. This example is appropriate for Linux tools. It is also possible to use Pin to examine binaries without instrumenting them. This is useful when you need to know static properties of an image. The sample tool below counts the number of instructions in an image, but does not insert any instrumentation. Control is returned to the original uninstrumented code and the application runs at native speed.
Thereafter no instrumented code is ever executed. Probe mode is a method of using Pin to insert probes at the start of specified routines. A probe is a jump instruction that is placed at the start of the specified routine.
The probe redirects the flow of control to the replacement function. Before the probe is inserted, the first few instructions of the specified routine are relocated.
It is not uncommon for the replacement function to call the replaced routine. Pin provides the relocated address to facilitate this. See the example below. In probe mode, the application and the replacement routine are run natively.
This improves performance, but it puts more responsibility on the tool writer. Probes can only be placed on RTN boundaries. In particular, the Pin thread APIs are not supported in Probe mode, because Pin has no information about the threads when the application is run natively. The tool writer must guarantee that there is no jump target where the probe is placed. A probe may be up to 14 bytes long. Also, it is the tool writer's responsibility to ensure that no thread is currently executing the code where a probe is inserted.
Tool writers are encouraged to insert probes when an image is loaded to avoid this problem. Pin will automatically remove the probes when an image is unloaded. To build this test, execute:. Pin allows Pintools to register for notification callbacks around forks. This example instruments a program to count the total number of instructions discovered and executed. The instructions are divided to three categories: native instructions, dynamic instructions and instructions without any known routine.
Following example instruments a program to log Jitting and running of dynamic functions which are reported by Jit Profiling API. The examples in the previous section have introduced a number of ways to register callback functions via the Pin API, such as:. The extra parameter val shared by all the registration functions will be passed to fun as its second argument whenever it is "called back".
This is a standard mechanism used in GUI programming with callbacks. If this feature is not needed, it is safe to pass 0 for val when registering a callback. The expected use of val is to pass a pointer to an instance of a class. Since val is a generic pointer, fun must cast it back to an object before dereferencing the pointer. Although Pin is most commonly used for instrumenting applications, it is also possible to change the application's instructions.
Note that in all of the cases where an instruction is modified, the modification is only made after all of the instrumentation routines have been executed. Therefore all of the instrumentation routines see the original, un-modified instruction.
Pin's advanced debugging extensions allow you to debug an application, even while it runs under Pin in JIT mode. This allows you to interactively control your Pintool from within a live debugger session. Finally, Pintools can add powerful new debugger features that are enabled via instrumentation.
For example, a Pintool can use instrumentation to look for an interesting condition like a memory buffer overwrite and then stop at a live debugger session when that condition occurs.
The Pin APIs are the same in all cases, but their usage from within the debugger may differ because each debugger has a different UI. The following tutorial is divided into two sections: one that is Linux and macOS centric and another that is Windows centric.
They both describe the same example, so you can continue by reading either section. Finally, note that these advanced debugging extensions are not at all related to debugging your Pintool. If you have a bug in your tool and need to debug it, see the section Tips for Debugging a Pintool instead. Throughout this section, we demonstrate the debugging extensions in Pin with the example tool "stack-debugger. You may want to compile that tool and follow along:.
The tool and its associated test application, "fibonacci", are built in a directory named "obj-ia32", "obj-intel64", etc. To enable the debugging extensions, run Pin with the -appdebug command line switch. This causes Pin to start the application and stop immediately before the first instruction.
Pin then prints a message telling you to start debugger. At this point, the debugger is attached to the application that is running under Pin. You can set breakpoints, continue execution, print out variables, disassemble code, etc. Of course, any information you observe in the debugger shows the application's "pure" state. The details of Pin and the tool's instrumentation are hidden.
For example, the disassembly you see above shows only the application's instructions, not any of the instructions inserted by the tool. However, when you use commands like "cont" or "step" to advance execution of the application, your tool's instrumentation runs as it normally would under Pin. The previous section illustrated how you can enable the normal debugger features while running an application under Pin.
Now, let's see how your Pintool can add new custom debugger commands, even without changing the debugger itself. Custom debugger commands are useful because they allow you to control your Pintool interactively from within a live debugger session.
For example, you can ask your Pintool to print out information that it has collected, or you can interactively enable instrumentation only for certain phases of the application. That API sets up the following call-back function:. For example, the code snippet above implements the new commands "stats" and "stacktrace on". You can execute these commands in the debugger by using the "monitor" command:. A Pintool can do various things when the user types an extended debugger command.
For example, the "stats" command prints out some information that the tool has collected. Any text that the tool writes to the "result" parameter is printed to the debugger console. Note that the CONTEXT parameter has the register state for the debugger's "focus" thread, so the tool can easily display information about this focus thread. Finally, if that doesn't solve your problem, feel free to post a message to the newsgroup don't forget to include your Pin kit number, operating system, processor, and gcc version.
Performance varies by use, configuration and other factors. Learn more at www. Skip To Main Content. Safari Chrome Edge Firefox.
0コメント