Apart from error codes, error strings and logs, are there any other features which can be incorporated in the code to increase getting debug / trace information during code runtime which can help debug issues (or let us know what is going on) at runtime?
+2
A:
- Build without optimization, to preserve as much of the "intent" of the code as possible
- Build in debug mode, to add symbol information
- Don't strip the executable (on Linux/Unix systems), to keep as much symbol information as possible for debuggers to use
unwind
2010-02-01 15:12:20
+1
A:
When building for Linux, I like to be able to print a stack backtrace from a signal handler. This helps debug crashes (SIGSEGV
) or allows me to send a signal to the program to initiate a stack backtrace at runtime. Core dumps can also be useful in debugging crashes (again in Linux).
jschmier
2010-02-01 15:17:33
Will this work for multi-threaded code? Also, if I have a library as a deliverable, can I add this in that also? Won't this interfere with the application's signal handler if present?
Jay
2010-02-01 15:33:22
Signal handlers are shared between all threads: when a thread calls sigaction(), it sets how the signal is handled not only for itself, but for all other threads in the program as well. You can also look into the backtrace(3) functions.
jschmier
2010-02-01 15:43:35