Core dump in Linux

后端 未结 5 1279
深忆病人
深忆病人 2020-12-28 09:15

I want to create a core dump whenever my process crashes. Currently I am following this approach:

  1. Build a special \"debug\" version of the program using \"-g\"
5条回答
  •  生来不讨喜
    2020-12-28 09:28

    1. There is no such thing as a "release" version and "debug" version on Linux. You just build a program with debugging information when use "-g". You can strip this information.

    Updated
    Actually I think I should say about one possible difference between debug and release versions that I didn't mention in my message. Release versions might be built with the NDEBUG define in order to get rid of all assert() in the program. Debug versions on the contrary should be built without defining NDEBUG as assert() helps in finding bugs.

    However if you don't use assert() there will be no difference.

    1. A user can set ulimit -c unlimited in his or her profile.

    2. Backtrace of an program compiled with some optimization often doesn't give a line number which is useful.

    3. You can build a version with debugging information and put in your archive. Then strip it and deliver the stripped binaries to your customers. If a customer gives you a core file then just use the version with debugging information and the core file from the customer.

    4. How to create a core dump in the "release" build of a program? It's not your responsibility, it's responsibility of the OS.

提交回复
热议问题