How to save the output of the following command to a text file so that I can write an analyzer?
(gdb) x/10000000s 0x20000000
This is actually quite simple:
(gdb) set height 0
Voila, enjoy your gdb.txt to gdb.txt .
I have a buggy (leaked memory) software .... "Save gdb formatted output to a file and run pattern matching to see which magic string is best suited."
This idea is unlikely to give satisfactory results. Consider:
void some_function() { std::vector<string> *v = new std::vector<string>();
Even if you can effectively βsee the magic line that fits bestβ, you will find that you leak all the lines; but this is not a problem, the problem "v" is a problem.
So, you really want to build a graph in which the selected regions point to other selected areas, and find the "root" of this graph. This is almost impossible to do manually.
So, which is more likely to help you find a memory leak? Fortunately, there are many tools that can solve this problem for you:
Employed Russian
source share