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

前端 未结 2 487
滥情空心
滥情空心 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:24

    Run your program under GDB. When the segfault occurs, GDB will inform you of the line and statement of your program, along with the variable and its associated address.

    You can use the "print" (p) command in GDB to inspect variables. If the crash occurred in a library call, you can use the "frame" series of commands to see the stack frame in question.

提交回复
热议问题