如何使用gdb来探索栈/堆? [英] how to use gdb to explore the stack/heap?
问题描述
任何人都可以请给我一个快速概述/指向我的方式来检查堆栈文件(和堆?)一个C程序?我想这应该GDB来完成,但是如果有其他更简单明了的选择,那么应该罚款为好。
Could anyone please give me a quick overview/point me to documentation of a way to inspect the stack (and heap?) of a C program? I thought this should be done with GDB, but if there are other more straighforward alternatives, then that should be fine as well.
感谢。
推荐答案
我的第一个方法来使用GDB调试是设置断点。这是像这样做 -
My first approach to using GDB for debugging is to setup breakpoints. This is done like so-
prompt> gdb ./x_bstree.c
(gdb) #prompt
(gdb) b 123 #break at line 123
(gdb) r #start program
现在你的程序停止在程序的123行。现在,您可以使用打印
检查栈或堆变量。对于堆栈变量只使用打印<&VARNAME GT;
。对于堆变量(指针)使用打印< * VARNAME>
。不知道有什么特别的用于检查堆栈/堆变量办?
Now your program halts at line 123 of your program. Now you can examine variables in stack or heap using print
. For stack variables just use print <varname>
. For heap variables (pointers) use print <*varname>
. Not sure there is anything special to do for examining stack/heap variables?
当然,调试,你需要使它在单线程模式和运行放多线程应用程序;然后dubug否则就很难predict发生了什么。
Of course to debug multi-threaded applications you would need to make it run in single-threaded mode & then dubug Otherwise it becomes difficult to predict what's happening.
有关别的有一种 GDB &放大量的文档;许多网站也提供了 GDB小抄
For anything else there is extensive documentation of gdb & many sites also provide gdb cheat sheets
这篇关于如何使用gdb来探索栈/堆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!