Memory Dump

Hi all,

What is the best way to obtain a dump of cpu state(registers and pgm output) + memory state at the end of program execution using jit in llvm.
To get the memory state, I was thinking of writing a pass which reads the store instructions to find out pointers which are being modified and add instructions at the end of the program to dump the values.
To get the cpu state, I was thinking of writing a machine pass which would use the live interval analysis info to get a dump of live registers.

Is this approach correct. Please let me know if there is any better way of doing this and if I could use any other existing passes to get the same information. Any comments are welcome.

Thanks,
Bhavani