开发者

How to get valgrind to cooperate with libsigsegv?

开发者 https://www.devze.com 2023-02-11 22:55 出处:网络
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,

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,

  1. We set up a stack-overflow handler using libsigsegv.
  2. The handler leaves via sigsegv_leave_handler开发者_开发技巧(), which then returns to the interpreter's main loop via siglongjmp.

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?


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 the siglongjmp. Eventually you'll get SIGBUS, 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 where SIGBUS is delivered will likely help.

0

精彩评论

暂无评论...
验证码 换一张
取 消