c - gdb: set a breakpoint for a SIGBUS handler -
i'm trying debug simple stop-and-copy garbage collector (written in c) using gdb. gc works handling sigbus. i've set breakpoint @ top of sigbus signal handler. i've told gdb pass sigbus program. however, doesn't appear work.
the following program (explained inline) shows essence of problem:
#include <stdio.h> #include <sys/mman.h> #include <assert.h> #include <signal.h> #define heap_size 4096 unsigned long int *heap; void gc(int n) { signal(sigbus, sig_dfl); // debugging printf("gc time\n"); } int main () { // allocate twice required heap size (two semi-spaces) heap = mmap(null, heap_size * 2, prot_read | prot_write, map_anon | map_shared, -1, 0); assert (heap != map_failed); // 2nd semi-space unreadable. using "bump-pointer allocation", sigbus // tells out of space , need gc. void *guard = mmap(heap + heap_size, heap_size, prot_none, map_anon | map_shared | map_fixed, -1, 0); assert (guard != map_failed); signal(sigbus, gc); heap[heap_size] = 90; // pretend out of heap space return 0; }
i compile , run program on mac os x 10.6 , output expect:
$ gcc debug.c $ ./a.out gc time bus error
i want run , debug program using gdb. in particular, want set breakpoint @ gc function (really, gc signal handler). naturally, need tell gdb not halt on sigbus well:
$ gdb ./a.out gnu gdb 6.3.50-20050815 (apple version gdb-1346) (fri sep 18 20:40:51 utc 2009) ... snip ... (gdb) handle sigsegv sigbus nostop noprint signal stop print pass program description sigbus no no yes bus error sigsegv no no yes segmentation fault (gdb) break gc breakpoint 1 @ 0x100000d6f
however, never reach breakpoint:
(gdb) run starting program: /snip/a.out reading symbols shared libraries +. done program received signal exc_bad_access, not access memory. reason: kern_protection_failure @ address: 0x0000000100029000 0x0000000100000e83 in main () (gdb)
apparently, signal handler not invoked (gc time not printed). furthermore, we're still in main(), @ faulting mov:
0x0000000100000e83 <main+247>: movq $0x5a,(%rax)
any ideas?
thanks.
the same code (modified handle sigsegv too) works expected in gdb on linux; may bug in os x or gdb's port platform.
googling finds broken os x behavior yours way on 10.1, sort-of workaround (set inferior-bind-exception-port off
before running program).
(there's similar bug on windows.)
Comments
Post a Comment