Hello, Im new to this forum. This post is related to debugging.
I have encoutered many times that problem with GCC:
Using optimization flags (-O1 .. -O3) introduces bugs in the program.
The bug itself does not come from GCC optimisations, but from a mathematical inconstitency in the source code. The problem then is for debugging. For small source code it is often easy to isolate the function(s) with bugs and rewrite them. With larger source code, and especially with complex data structures, it is not obvious where the bug comes from. It might be possible to isolate buggy functions but the problem might not come from them, rather from other initialisation, pre-process or post-process functions. Sometimes the wrong computation is due to a data structure inconsitency, which is really hard to debug with common debuggers: the data structure may hold exactely what data you expect it to hold.
To sum up, I am in the worst case: large source code, complex data structures, no obvious bugs neither in the functions nor in the datas held by the structure. The mathematical model the program relies on does not seem to have inconstitencies either.
Since the ouput of the program was correct and I would never find out that there was a bug without changing compilation options, one would say I am facing a shroedinger bug :)
My question is: anyone have tips to deal with that sort bugs? Any debugging method to rely on?
Dreaming of an -OEXPLAIN option for GCC, ala SQL ;)