

Ask HN: How to programmatically observe program execution? - chris_l

I'm currently researching this interesting question and haven't found much material on it: How can one best programmatically observe the execution of a program, much like single-stepping it in the debugger, but wholesale and automatically?<p>Rigging up a debugger was my first idea, as they do the same thing for human consumption, but that doesn't seem to be a normal use scenario, and hence no APIs. Alternatively one could extend some virtualization software to capture what the processor is doing. I would settle for source modification, which would work for just capturing function calls, but that brings in other complications. Finally there's the issue of languages: I was thinking of simple C programs, although it would probably be easier in Java or Lisp, but I'd like to stay general.<p>Have you ever solved this or what approach would you try?
======
wmf
DTrace and SystemTap can insert probes in code if you're only interested in
certain parts. If you want basic-block-level or instruction-level coverage,
look at Pin, DynamoRIO, or Valgrind.

~~~
chris_l
Thanks, the latter two sound good. Pin seems to be a too generic acronym to
Google it, what does it stand for?

~~~
wmf
Ah, good point; it took me a few tries to find the site myself. Apparently Pin
isn't an acronym; it's just Pin.

<http://www.pintool.org/>

------
fauigerzigerk
Maybe something like dtrace? I'm not sure what your application scenario is
though.

~~~
chris_l
Thanks, meanwhile I have just stumbled up on ptrace which also looks
promising.

My application is to visualise the execution of programs, for which I want to
ideally capture everything the processor does and generalise what I see...

------
abecedarius
There's been research on this, e.g. <http://www.cs.nmsu.edu/~jeffery/alamo/>

That's about 10 years old, though, and I don't know what's been done since.

------
lacker
If you run your debugger via emacs, you should be able to use emacs macros to
programmatically observe execution.

