Line number of segmentation fault

前端 未结 8 1026
误落风尘
误落风尘 2020-12-13 08:56

Is there any gcc option I can set that will give me the line number of the segmentation fault?

I know I can:

  1. Debug line by line
  2. Put printfs in
8条回答
  •  醉话见心
    2020-12-13 09:01

    There is no method for GCC to provide this information, you'll have to rely on an external program like GDB.

    GDB can give you the line where a crash occurred with the "bt" (short for "backtrace") command after the program has seg faulted. This will give you not only the line of the crash, but the whole stack of the program (so you can see what called the function where the crash happened).

提交回复
热议问题