Line number of segmentation fault

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

    Here's a complete shell/gdb session

    $ gcc -ggdb myproj.c
    $ gdb a.out
    gdb> run --some-option=foo --other-option=bar
    (gdb will say your program hit a segfault)
    gdb> bt
    (gdb prints a stack trace)
    gdb> q
    [are you sure, your program is still running]? y
    $ emacs myproj.c # heh, I know what the error is now...
    

    Happy hacking :-)

提交回复
热议问题