How can I get GDB to tell me what address caused a segfault?

前端 未结 2 486
滥情空心
滥情空心 2020-12-07 17:24

I\'d like to know if my program is accessing NULL pointers or stale memory.

The backtrace looks like this:

Program received signal SIGSEGV, Segmentation f         


        
2条回答
  •  佛祖请我去吃肉
    2020-12-07 18:23

    With GDB 7 and higher, you can examine the $_siginfo structure that is filled out when the signal occurs, and determine the faulting address:

    (gdb) p $_siginfo._sifields._sigfault.si_addr
    

    If it shows (void *) 0x0 (or a small number) then you have a NULL pointer dereference.

提交回复
热议问题