Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gdb dump memory in specific region, save formatted output into a file

I have a buggy (memory leaked) software. As an evidence, I have 1GB of core.dump file. Heap size is 900MB, so obviously, something allocates, but does not free the memory.

So, I have a memory region to examine like this.

(gdb) x/50000s 0x200000000 

However, this is hard to guess only with naked eyes, which object or struct is not freed. My idea to trace is, "Save gdb formatted output into a file, and run a pattern match to see which magic string comes up the most." So, here is my question:

How can I save output of following command into a textfile, so that I can write an analyzer?

(gdb) x/10000000s 0x20000000    <-- I need this output into a file 
like image 858
dragonfry Avatar asked Apr 19 '13 01:04

dragonfry


People also ask

How to use examine in gdb?

You can use the command x (for “examine”) to examine memory in any of several formats, independently of your program's data types. Use the x command to examine memory.


1 Answers

You could use the "dump" function of gdb, see: https://sourceware.org/gdb/onlinedocs/gdb/Dump_002fRestore-Files.html

For your example:

dump binary memory result.bin 0x200000000 0x20000c350 

This will give you a plain binary dump int file result.bin. You can also use the following to dump it in hex format:

dump ihex memory result.bin 0x200000000 0x20000c350 

Using the dump command is much clearer than using the gdb logging hack (which even did not work for me somehow).

like image 141
eci Avatar answered Sep 29 '22 00:09

eci