I am modifying someone else's code on Linux, and I get some runtime errors. The programs are built with the -O3 option. I wish to debug with gdb and take advantage of as many features as possible, so -debug comes to mind, possibly -traceback
What would be the best combination of options to enable use of gdb? Would you recommend no -O options at all?
Turn on all checks at compile and run time, e.g. -Wall. Use one or more different compilers, e.g. NAG and/or gfortran. Check the array bounds etc. Usually -O0 is the best for debugging to avoid heavy optimisation, because optimisation oftentimes hinders the output of values and arguments of functions and subroutines in tracebacks and/or debugging sessions.
The advice about allowing debug to disable optimization at first is good. Eventually you may need to debug with all your optimization enabled Then you need -debug inline_debug_info but you will still find some symbols missing and some reordered operations. -fno-inline-functions will skip some optimizations and may help with debugging while avoiding requirement for inline_debug_info. We've seen programming errors which aren't exposed until interprocedural optimization is in use. Bounds checking (preferably without optimization) may catch such errors.