You need to compile debug build (with debug information turned on and optimizations turned off) and run the program under debugger to see if there are any runtime errors/asserts and what are the threads doing if the program hangs.
The -g flag itself does not affect the code generated. You probably just replace other flags with your assignment. You could compare the default command lines with command line you get when you add extra options to see what you could have overridden.
I suggest you configure as
Having passed "-g -fno-omit-stack-frames" to the compiler options and plain "-g" to the linker options you should be able to get debug symbols and see sources in debugger even with optimizations enabled. You need to find call stacks of major threads and determine whether they loop constantly or they are stuck somewhere.
This thread seems to be drawing triangles. You could break and continue program several times and thus see if a thread is always at the same execution address or it breaks in different places. If execution points vary, that means that the thread is most likely executing normally. You should check other threads.
Also, copy entire call stack, rather than the innermost frame alone.