A couple of days ago I needed to get the state of the cpu registers of a running process during some specific events. The project I was playing with was written in ruby so I wrote a tiny little module that does just that, gives you the value of the requested cpu register. The module is called reginfo and below is the process I followed to do it.
First I had to write the C part of it, for the instrumentation. A simple way to get the registers is to use ptrace. First we attach to a process, then we get the register, then we detach and finally return the value.
For this to work as a ruby module we have to use the ruby.h
Next it's straight forward, we create an extconf.rb file which when we execute generates the Makefile which will compile our module.
And an example
The above prints something like b7f577d8
You can download reginfo from here, the source code from here and project updates here.
This is a very simple linux module that performs only this specific task, more functionality will be added soon. If you are looking for something a bit more elaborate, have a look at METASM.