在GDB中,如何找出谁在堆上分配了地址?
我在 GDB 中有一个指针,如何找出它在堆上首次分配的位置?
在 WinDBG 中,可以在打开 gflags /i <*exe> 后通过
!heap -p -a <0x12345678>
来完成此操作。 +ust
由于 Valgrind 可以告诉我内存分配在哪里(当它检测到一些泄漏时),我想这也是可能的?
(这与观察点无关。这是给定的情况,我随机闯入GDB中的应用程序,查看指针并想知道“谁创建了这块内存”?)
在GDB中使用反向调试是一种非常新颖的方法方法,并且可能是解决此问题的正确方法。我在使用 GDB 7.1(最新的稳定版本)时遇到了一些问题。反向调试是 GDB 中的一项相当新的功能,因此我需要检查 HEAD (7.2) 来修复它。
它可能说明了 GDB 方法的成熟度,但我认为当它更成熟时绝对应该使用它。 (很棒的功能!)
I have a pointer in GDB, how can I find out where it was first allocated on the heap?
In WinDBG, this can be done by !heap -p -a <0x12345678>
after turning on gflags /i <*exe> +ust
Since Valgrind can tell me where the memory is allocated (when it detects some leaks), I guess this is also possible?
(This is NOT about watchpoint. This is given the situation where I randomly break into the In GDB, application, look at a pointer and want to know "who created this piece of memory"?)
Using reverse debugging in GDB is a very novel way and probably the correct way to solve this problem. I encountered some problem with that approach with GDB 7.1 -- the latest stable version. Reverse debugging is a rather new feature in GDB so I needed to check out HEAD (7.2) to fix it.
It probably says something about the matureness of the GDB approach but I think it should definitely be used when it's more mature. (Awesome feature!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许反向调试会在这里有所帮助。尝试在内存地址上设置观察点并反向继续直到内存写入。
Maybe reverse debugging will help here. Try to set watchpoint on memory address and reverse-continue until memory written.
Valgrind 劫持内存管理调用,这就是堆检查器的工作原理。 GDB 本身没有任何工具可以告诉您
malloc(3)
返回给定地址的位置。我建议查看 mtrace 和 glibc 分配调试。Valgrind hijacks memory management calls, that's how heap checkers work. There's no facility in GDB itself to tell you where given address was returned by
malloc(3)
. I suggest looking into mtrace and glibc allocation debugging.record 确实在 Hello World 程序上运行。
哎呀我用record来调试gdb本身!
record DOES run on a Hello World program.
Heck I use record to debug gdb itself!