6 ms·
Pin - A Dynamic Binary Instrumentation Tool
- interconnector 14y agoDiscussed at greater depth in the paper at http://goo.gl/YDTwu http://goo.gl/YDTwu , if anyone's interested.
- xal 14y agoHere is an actual Hacker tool that allows all sorts of insane CPU close performance work. No comments all day. This is heartbreaking.
- tptacek 14y agoSo... what do you think about it? Or, do you have questions? I'm not very familiar with Pin, but am somewhat familiar with DynamoRIO, which is a competing project.
- lallysingh 14y agoFirst, it's Sunday night. Second, PIN gives you very low-level access, sure, but it also requires quite a bit of work to get that data. You can get a lot of the same data (as seen in the examples) with libpfm4 (http://perfmon2.sourceforge.net/ http://perfmon2.sourceforge.net/). CPU Performance counters can give you a lot of this data with much lower run-time overhead, and a lot less work. Also, PIN's a little hairy. If you just want to generate code for run-time execution, LLVM's your best bet. If you want to diddle with a running executable, you can always use libelf(3) and ptrace(2) to read and diddle with the running process. It may be useful for specific sorts of analyses you want to run on an executable, but it's messy. If you're doing performance instrumentation, dynamically modifying the code is going to alter your results that can be hard to compensate for.
- tptacek 14y agoYou can't effectively do things like instrumenting every write instruction in a program using ptrace. Also, the techniques Pin uses sound hairy, but they're the same things software virtualization does.
- lallysingh 14y agoTrue, but what do you do with that data? Transfer it out of process? Analyze it? And how many systems can withstand that sort of slowdown without timeouts? Performance counters can tell you quite a bit, and they cost very little to set up. Snapshots and a little differential analysis can get you more comprehend-able data without transfer/storage problems.
- nkurz 14y agoI came across it as a platform for running and debugging code for a non-yet-released CPU: http://software.intel.com/en-us/articles/intel-software-development-emulator http://software.intel.com/en-us/articles/intel-software-deve... A couple other uses that I thought it would be good for were marking instructions with unaligned loads and stores and flagging switches to and from 256-bit VEX code. Although probably you can do these with other tools as well. I posted this here because it seemed potentially useful, and I was surprised I'd never heard of this project. I'm mostly familiar with the ones Lally mentioned, but Thomas brought up DynamoRIO which is also new to me. Are there other niche optimization tools I should know about? A specific question would whether there is anything more useful than IACA and gut instinct for determining optimal instruction order. Even just something that would generate an easy to parse data dependency graph for a short section of code?
- lgeek 14y agoI think it's all about using the right tool for the right job. Sure enough, there are some things that dynamic binary modification(DBM) does that can also be implemented another way (e.g. generic application level profiling), but even some of those things are sometimes done faster/better by DBM tools: Want to log the system calls to RANDOM_SYSCALL? Sure, use ptrace and do these context switches: app>kernel>ptrace_app>kernel(actual syscall)>ptrace_app>kernel>app every time any system call executes... Or use PIN and take the usually small performance hit. ptrace also messes up signal delivery. Want to profile dynamically generated code? libelf won't be much help there. Or do you want to run memory accesses through a cache simulator? ptrace won't be much help. There are plenty of uses when DBM is the right (or only) tool.
- caf 14y agoThe user guide gives a good flavour of the kind of things you can do with this ( http://software.intel.com/sites/landingpage/pintool/docs/58423/Pin/html http://software.intel.com/sites/landingpage/pintool/docs/584... ).
- smtddr 14y agoThis is definitely something I won't forget about the next time I'm trying to figure out what a binary is exactly doing. Also, I really need something like this for OSX right now.
- tptacek 14y agoI believe people are working on a port of DynamoRIO to OSX.
- k4st 14y agoI am working on a DBT framework that has some user space support. I do my main development in OS X and Linux, and so I have done some testing of it on OS X. The main focus of the DBT tool is Linux kernel modules, but let me know the kinds of stuff you need it for and I can a) figure out if my tool is applicable, and b) perhaps share the code.
- smtddr 14y ago/Applications/Xcode.app/Contents/Developer/usr/bin/instruments I need to know everything about that binary. How it works, what ports(unix domain & network sockets), files it opens on the harddrive, libraries it's linked to, how it decides what to do. Anything & Everything there is to know about it. ^_^
- k4st 14y agoI will look into this a bit tomorrow. Can you supply an example command-line invocation?
- smtddr 14y agohttp://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-... This blog talks about the tool for automated testing. It's kinda "complicated" to setup. In the blog, he eventually gets to a commandline: instruments -t /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate "/Users/jc/Library/Application Support/iPhone Simulator/5.1/Applications/C28DDC1B-810E-43BD-A0E7-C16A680D8E15/TestAutomation.app" -e UIASCRIPT /Users/jc/Documents/Dev/TestAutomation/TestAutomation/TestUI/Test-2.js But there's a lot of setup, so =/
- nnethercote 14y agoHere's a paper about Valgrind that includes some details on how it differs from Pin: http://www.valgrind.org/docs/valgrind2007.pdf http://www.valgrind.org/docs/valgrind2007.pdf.
- cwp 14y agoHow does this compare to dtrace?
- rainforest 14y agoThey differ quite significantly. dtrace uses probes - points where instrumentation can be installed to inspect the process as it runs. Since it requires these probes to be defined, probes only come "for free" in kernel-space: e.g. tracing syscalls, pageins, that kind of thing. SystemTap offers similar functionality - userspace probes can be defined for it too. Pin, on the other hand, dynamically rewrites the binary to inject instrumentation. This allows it to inject instrumentation code at a higher granularity (individual instructions). It's useful where the application might not define dtrace probes, or, for example on OSX, where the application has "opted out" of it to protect it from being screenshotted (a la iTunes). Pin is more like a scripted debugger than an instrumentation tool.
- cwp 14y agoAh, very clear. Thank you.
- mspecter 14y agoAn interesting application of Pin for malware analysis / visualization is Danny Quist's Vera[1] and de-obfuscation framework[2]. It's also used in MIT's Architecture course to benchmark different architecture designs. [1] http://www.offensivecomputing.net/?q=node/1687 http://www.offensivecomputing.net/?q=node/1687 [2] http://www.offensivecomputing.net/?q=node/492 http://www.offensivecomputing.net/?q=node/492
- zokier 14y ago> Pin is proprietary software developed and supported by Intel and is supplied free of charge for non-commercial use. Huh. What are the licensing conditions and price for commercial use then?
- lgeek 14y agoIf this is a concern, feel free to use the open source, BSD-licensed main competitor: DynamoRIO: http://www.dynamorio.org/ http://www.dynamorio.org/
- qznc 14y agoIsn't valgrind a more popular competitor?
- lgeek 14y agoPIN/DynamoRIO and Valgrind have slightly different design aims. In short: * Valgrind was designed to support rich analysis plugins (like Memcheck, which keeps a shadow copy of every bit of data) and performance was a secondary concern (on Valgrind, applications run on average about 4x slower, threads are serialized, etc). * DynamoRIO and PIN are designed not to make much of an impact on performance (usually a few percent) and are more suitable for running in production, but it's somewhat more complicated to write plugins for them. Both DynamoRIO[0] and Valgrind[1] maintain lists of publications which go into much more detail. [0] http://www.dynamorio.org/pubs.html http://www.dynamorio.org/pubs.html [1] http://valgrind.org/docs/pubs.html http://valgrind.org/docs/pubs.html