gdb,转储内存,将格式化输出保存到文件中 [英] gdb, dump memory, save formatted output into a file
问题描述
作为证据,我有1GB的core.dump文件。堆大小为900MB,显然,分配的东西,但不释放内存。
所以,我有一个内存区域来检查像这样。
(gdb)x / 50000s 0x200000000
然而,这仅仅是肉眼难以猜测的,哪个对象或结构没有被释放。
我的想法是:将gdb格式化的输出保存到一个文件中,然后运行模式匹配查看哪个魔法字符串出现最多。所以,这里是我的问题:
如何将以下命令的输出保存到文本文件中,以便我可以编写分析器?
(gdb)x / 10000000s 0x20000000< - 我需要输出到文件
感谢您的任何帮助。 您可以使用转储gdb的功能,请参阅: https://sourceware.org/gdb/onlinedocs/gdb/Dump_002fRestore-Files .html
例如:
转储二进制内存result.bin 0x200000000 0x20000c350
这会给你一个普通的二进制转储int文件 result.bin
。您还可以使用以下内容以十六进制格式转储它:
转储ihex内存result.bin 0x200000000 0x20000c350
使用dump命令比使用gdb日志记录hack更清晰(它甚至不会为我工作) p>
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 don't 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
Thank you for any help.
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).
这篇关于gdb,转储内存,将格式化输出保存到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!