What's your method for finding the cause of a segfault?

后端 未结 6 372
不知归路
不知归路 2021-01-14 07:51

Or just debugging in general, how do you like to go about finding bugs in code. Specifically for C/C++, but all languages in general. I\'ve been trying to find the cause of

6条回答
  •  鱼传尺愫
    2021-01-14 08:14

    RMS made a good tutorial for finding a segfault using gdb.

    Short version:

    $ gcc -g -O0 -o program program.c # -O0 makes debugging easier
    $ gdb ./program
    > run # Tell gdb to start running the thing
    ...segfault happens
    > bt # Get a stack trace from where it segfaulted
    

提交回复
热议问题