Line number of segmentation fault

前端 未结 8 974
误落风尘
误落风尘 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:08

    Run it under valgrind.

    0 讨论(0)
  • 2020-12-13 09:22

    I don't know of a gcc option, but you should be able to run the application with gdb and then when it crashes, type where to take a look at the stack when it exited, which should get you close.

    $ gdb blah
    (gdb) run
    (gdb) where
    

    Edit for completeness:

    You should also make sure to build the application with debug flags on using the -g gcc option to include line numbers in the executable.

    Another option is to use the bt (backtrace) command.

    0 讨论(0)
提交回复
热议问题