How to fix crashes in release builds or how to enable debug information in release builds for VC projects?
I will explain very briefly, how to fix crashes in release builds of VC applications.
Difference between debug and release builds
Well so what’s the difference between release and debug builds? The only major difference is that debug builds are for debugging purpose and release builds are for end users so for this purpose debug builds contain additional debug information, this is why there is considerable size differences in binaries for debug and release.
Common reasons for crashes in release builds
Well not too many steady reasons for crashes in release builds, but some to think of I will list here…
- Uninitialized variables
- Uninitialized pointers
- Always set a pointer to NULL after deletion
- Invalid iterators (std::iterator)
- Crap code
- Array index out of bounds for array and other stl classes.
- Too much optimization.
- RTTI project settings.
Check out above reasons if there is a crash in your release builds.
So tell us how to fix issues in release builds
- Learn assembly. 😛 Joking! Naah not everyone has time to learn assembly but hey it’s good to have basic knowledge on this topic.
- Enable debug information for your release binaries. Ha, but will this increase the size of my release binaries. Nope! An extra file called a pdb (Program database) is created, which helps the JIT or any debugger to list out symbols used in your applications.
- Always keep an updated set of symbols for all binaries; debuggers do download them automatically if you set _NT_SYMBOL_PATH to point to a symbol server. More information on how to set a symbol path is here.
- Stop writing crap code.
Make my release build a debug build
If you are in the process of development and then you notice a crash while testing release build and you don’t know where the crash is taking place, do the following…
- Enable debugging for your release builds
- Go to C-C++/Optimizations/ and select Disable(Debug). If you don’t enable this bit you will see weird behavior while debugging. For e.g. addresses show as NULL even for valid objects on stack. By the way this might even be the cause of those crashes so initially you can leave it as it is but watch out for weird behaviors, don’t be surprised.
- Go to C-C++/Debug Info/ and select Program Database, this will generate a pdb file.
- If the output for a particular project is of .lib type then this much will suffice.
- Now for dlls and exes, follow steps 1 – 3.
- Go to Link tab/section and enable “Generate debug info”, this will add further debugging information to your exe or dll. Will show real deep stack traces with values of passed in parameters.
Yup now your release exe/dll/lib is now in full fledged debugging form. An additional thing to note is that _DEBUG is not enabled so AfxTrace, TRACE, TRACE0, TRACE1, TRACE2, ASSERTs, and VERIFYs won’t work.
Hope this helps you guys! 🙂