gdb: set a breakpoint for a SIGBUS handler

前端 未结 4 1967
孤独总比滥情好
孤独总比滥情好 2021-02-08 20:14

I\'m trying to debug a simple stop-and-copy garbage collector (written in C) using GDB. The GC works by handling SIGBUS. I\'ve set a breakpoint at the top of my SIGBUS signal ha

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-08 20:34

    Why do you expect to get a SIGBUS? SIGBUS usually means alignment error, on an architecture where some datatypes have alignment requirements. It looks like you are just trying to access memory outside your allocated area, and I would expect that you get SIGSEGV instead of SIGBUS then.

    Edit:

    It seems that the Mac OS X name for what I think of as SIGSEGV is SIGBUS. Therefore, ignore this answer.

    If it's any help, the breakpoint works as expected (i.e., it works) when I try the program on a Linux system, with SIGBUS replaced by SIGSEGV.

    Edit 2:

    Can you try to catch SIGSEGV in your program too? It seems that the type of signal may vary depending on where the memory is mapped in Mac OS X (I just read the discussion here and here), and just perhaps a different signal could be thrown when you run in the debugger?

提交回复
热议问题