Line number of segmentation fault

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.

Leave a Comment