GCC, which can cause debugging problems with GDB

I was wondering if I can get a list of gcc options that could cause gdb to behave strangely.

Of course, we all know that using optimization options (like -O3) causes weird behavior in gdb, but what are the other options that might have such an effect?

(I'm currently trying to start the mpeg2 decoder in gdb, and I get weird behavior even after removing the optimization flags ...)

+7
gcc flags gdb
source share
2 answers

It's hard for me to say which flags you should use when calling gcc for debugging. gcc docs note that the default debug flags are -g and -O2 , and using -g -O0 -fno-inline disables any optimization and attachment function.

In my opinion, if you really want to guarantee that nothing will ruin your debugging process, you just need to compile the -g -O0 -fno-inline flags.

+9
source share

As stated in the GCC documentation , you should use -Og:

-OG

Optimize your debugging experience. -Og allows optimizations that do not interfere with debugging. This should be the optimal level of choice for the standard editing-compilation-debugging cycle, offering a reasonable level of optimization while maintaining fast compilation and good debugging work.

It also describes each optmization flag and how it can affect debugging.

0
source share

All Articles