www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Dumping the contents of memory to a file

reply "Lewis" <musicaljelly gmail.com> writes:
I was wondering if there was a way to dump the contents of the 
heap to a file.

If the heap is guaranteed to be in one contiguous chunk, then all 
I would need is:

- The start address of the heap
- The current size of the heap

If it is not in one contiguous chunk, then it might be a little 
more complicated.

I'm okay with writing out way more data than needed, I don't need 
to compress anything or remove unused but allocated space. This 
is for a debugging tool, and so can be a little hacky.

Is this feasible? Does the request make sense?

Thanks!
Aug 19 2015
parent "qznc" <qznc web.de> writes:
On Wednesday, 19 August 2015 at 19:05:09 UTC, Lewis wrote:
 I was wondering if there was a way to dump the contents of the 
 heap to a file.

 If the heap is guaranteed to be in one contiguous chunk, then 
 all I would need is:

 - The start address of the heap
 - The current size of the heap

 If it is not in one contiguous chunk, then it might be a little 
 more complicated.

 I'm okay with writing out way more data than needed, I don't 
 need to compress anything or remove unused but allocated space. 
 This is for a debugging tool, and so can be a little hacky.

 Is this feasible? Does the request make sense?
You could enable core dumping (ulimit -c unlimited), crash the program, and let Linux do it for you. If you want to program continue to run, then it becomes interesting. Are there more threads? You probably want to stop them, so nobody modifies the heap while you dump it. Apart from that, just look at how to do it in C. https://stackoverflow.com/questions/3565232/how-to-programmatically-get-the-address-of-the-heap-on-linux
Aug 19 2015