如何让valgrind与libsigsegv配合?
正如这个关于使用 libsigsegv 检测多个堆栈溢出的问题中所述,我正在与一位同事合作尝试检测并从中恢复解释器中的堆栈溢出。简而言之,
- 我们使用 libsigsegv 设置了一个堆栈溢出处理程序。
- 处理程序通过 sigsegv_leave_handler() 离开,然后通过 siglongjmp 返回到解释器的主循环。
此设置成功检测到第一次堆栈溢出,但第二次堆栈溢出导致总线错误。我想用 valgrind 解决这个问题,但是 valgrind 在第一个段错误处接管。因此我的问题是 如何让valgrind
让libsigsegv
处理第一个段错误,然后接管内存检查?
As noted in this question about using libsigsegv to detect multiple stack overflows, I'm working with a colleague to try to detect and recover from stack overflow in an interpreter. In brief,
- We set up a stack-overflow handler using
libsigsegv
. - The handler leaves via
sigsegv_leave_handler()
, which then returns to the interpreter's main loop viasiglongjmp
.
This setup successfully detects the first stack overflow, but the second stack overflow leads to a bus error. I would like to hit this problem with valgrind, but valgrind takes over at the first segfault. My question is, therefore
how can I get valgrind
to let libsigsegv
handle the first segfault, then take over memory checking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Valgrind 是调试这个问题的错误工具——您可能不会遭受堆损坏(这是 Valgrind 的强项),而是受到其他原因的影响。
我会使用 GDB 来调试它。当您点击第一个
SIGSEGV
时,GDB 将停止。您可以要求它使用(gdb)信号SIGSEGV
将信号传递给应用程序,此时您的解释器将执行siglongjmp
。最终你会得到SIGBUS
,并且可以调试你是如何到达那里的。由于您可能使用 Linux,请注意
SIGBUS
相当罕见,通常是由于尝试访问根本未映射或保护错误的内存而导致的。在传送SIGBUS
时检查/proc//maps
可能会有所帮助。Valgrind is the wrong tool to debug this problem -- you are likely suffering not from heap corruption (which is what Valgrind is great at), but from something else.
I would use GDB to debug this. When you hit the first
SIGSEGV
, GDB will stop. You can ask it to deliver the signal to the application with(gdb) signal SIGSEGV
, at which point your interpreter will execute thesiglongjmp
. Eventually you'll getSIGBUS
, and can debug how you got there.Since you are likely on Linux, note that
SIGBUS
is rather rare, and usually results from trying to access memory that is either not mapped at all, or with wrong protections. Examining/proc/<pid>/maps
at the point whereSIGBUS
is delivered will likely help.